This directory contains runnable examples and shared helpers.
Warning: The Resource Owner Password flow is not recommended for production use. It bypasses modern MFA protections. Prefer DirectAuth when available.
- Create an okta.json or okta.ini configuration file in the repo root (or set
OKTA_CLIENT_CONFIG).
Example okta.json:
{
"issuer": "https://example.com",
"client_id": "client-id",
"scope": "openid profile"
}- Run the sample:
python -m samples.resource_owner --config okta.iniAdd --verbose to log raw requests and responses:
python -m samples.resource_owner --config okta.ini --verbose
To supply test credentials from JSON (for CI), use `--test-config`:
```bash
python -m samples.resource_owner --config okta.json --test-config test-configuration.jsonYou will be prompted for a username and password. The sample will exchange credentials for a token and print the token details.
- Create an okta.json or okta.ini configuration file in the repo root (or set
OKTA_CLIENT_CONFIG). - Run the sample with a subject token:
python -m samples.token_exchange \
--config okta.json \
--subject-token "$SUBJECT_TOKEN" \
--subject-type access_tokenOptional actor token:
python -m samples.token_exchange \
--config okta.json \
--subject-token "$SUBJECT_TOKEN" \
--subject-type access_token \
--actor-token "$ACTOR_TOKEN" \
--actor-type id_tokenOptional parameters (audience/resource/scope/requested token type):
python -m samples.token_exchange \
--config okta.json \
--subject-token "$SUBJECT_TOKEN" \
--subject-type access_token \
--audience api://default \
--resource https://resource.example.com \
--scope "openid profile" \
--requested-token-type access_tokenAdd --verbose to log raw requests and responses. Use --test-config to supply token values from JSON in CI.
- Create an okta.json or okta.ini configuration file in the repo root (or set
OKTA_CLIENT_CONFIG). - Run the sample with a refresh token:
python -m samples.refresh_token \
--config okta.json \
--refresh-token "$REFRESH_TOKEN"Optional scope and additional parameters:
python -m samples.refresh_token \
--config okta.json \
--refresh-token "$REFRESH_TOKEN" \
--scope "openid profile" \
--param device_secret=my-device-secretAdd --verbose to log raw requests and responses. Use --test-config to supply the refresh token from JSON in CI.
- Create an okta.json or okta.ini configuration file in the repo root (or set
OKTA_CLIENT_CONFIG). - Run the sample with a pre-built assertion:
python -m samples.jwt_bearer \
--config okta.json \
--assertion "$JWT_ASSERTION"Or generate an assertion using local key material:
python -m samples.jwt_bearer \
--config okta.json \
--jwt-issuer client-id \
--jwt-subject client-id \
--jwt-audience https://example.com/token \
--jwt-expires-in 300 \
--jwt-key-file ./private.pem \
--jwt-algorithm RS256Add --param for additional token request parameters. Add --verbose to log raw requests and responses.
Generate an assertion from a JSON claims payload and a PEM key file:
python -m samples.jwt_assertion \
--claims-file ./claims.json \
--key-file ./private.pem \
--algorithm RS256Or pass the claims as JSON:
python -m samples.jwt_assertion \
--claims-json '{"iss":"client","sub":"client","aud":"https://example.com/token","exp":1234567890}' \
--key "my-shared-secret" \
--algorithm HS256- Logging listener: samples/common/logging_listener.py
- Avoid using real production credentials.
- Do not commit secrets or credentials.