Skip to content

Instantly share code, notes, and snippets.

@noinarisak
Last active November 17, 2021 14:58
Show Gist options
  • Save noinarisak/fe23c02c96f6cc942fb021ca868755c1 to your computer and use it in GitHub Desktop.
Save noinarisak/fe23c02c96f6cc942fb021ca868755c1 to your computer and use it in GitHub Desktop.
Okta client credential flow example in bash
#!/usr/bin/env bash
set -e
# More details at https://bit.ly/3FlOmYd
# Update and set the client_id and client_secrect
client_id=_GET_THIS_FROM_YOUR_APP_GENERALS_SCREEN_
client_secret=_GET_THIS_FROM_YOUR_APP_GENERALS_SCREEN_
# Update the Okta root domain url and GUID Authorization Server (NOTE: Okta default is call 'default')
okta_root_url=narisak.okta.com
okta_auth_server_id=default
basic_auth=$(echo -n "${client_id}:${client_secret}" | base64)
echo "## Base64 encode 'client_id:client_secret'"
echo "${basic_auth}"
echo "## POST /token to get JWT"
curl --location --request POST "https://${okta_root_url}/oauth2/${okta_auth_server_id}/v1/token" \
--header 'Accept: application/json' \
--header "Authorization: Basic ${basic_auth}" \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=service_api'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment