In this example, create a web app that supports the authorization code with PKCE flow and refresh tokens.
Access Gateway generates the clientId and clientSecret for your app. You don't set these values yourself. Retrieve them after you create the app. See Retrieve the client secret.
- Retrieve your
idpIdby using the List all IdPs endpoint. Select the IdP that has failover mode set toAUTOMATIC. You need this value to create the app. - Create the OIDC app in Access Gateway by sending a
POSTrequest to the Create an application endpoint. Use the following request example as a template. - In the request body, set the following values for your app:
- Set
labelas the display name for the app. - Set
idpIdto the value that you retrieved in the first step. - In the
oidcobject, setapplicationTypetoweb,native, orspa. - In the
oidcobject, setredirectUrisas your client app's callback URL. - In the
oidcobject, forallowedScopes, include any combination ofopenid,profile,email, andoffline_access. This determines which scopes the app can request. - In the
oidcobject, foraccessTokenLifetimeandrefreshTokenLifetime, set the desired values in seconds. These determine how long tokens issued for this app are valid. [[style="list-style-type:lower-alpha"]]
- Set
- Send the POST request.
curl -i -X POST \
'https://{oaghostname}/api/v2/apps' \
-H 'Authorization: Bearer <YOUR_JWT_HERE>' \
-H 'Content-Type: application/json' \
-d '{
"type": "OAG_OIDC",
"label": "Test OIDC App - Auth Code",
"description": "OIDC app using authorization code flow with PKCE",
"idpId": "<idp-id>",
"oidc": {
"applicationType": "web",
"redirectUris": [
"https://example.com/callback"
],
"responseTypes": [
"code"
],
"grantTypes": [
"authorization_code",
"refresh_token"
],
"tokenEndpointAuthMethod": "client_secret",
"pkceRequired": true,
"allowedScopes": [
"openid",
"profile",
"email",
"offline_access"
],
"accessTokenLifetime": 3600,
"refreshTokenLifetime": 86400
}
}'{
"id": "app-oidc-123",
"type": "OAG_OIDC",
"label": "Test OIDC App - Auth Code",
"description": "OIDC app using authorization code flow with PKCE",
"status": "ACTIVE",
"idpId": "<idp-id>",
"oidc": {
"applicationType": "web",
"clientId": "<generated-client-id>",
"redirectUris": [
"https://example.com/callback"
],
"responseTypes": [
"code"
],
"grantTypes": [
"authorization_code",
"refresh_token"
],
"tokenEndpointAuthMethod": "client_secret",
"pkceRequired": true,
"allowedScopes": [
"openid",
"profile",
"email",
"offline_access"
],
"accessTokenLifetime": 3600,
"refreshTokenLifetime": 86400,
"clientCredentialsEnabled": false
},
"_embedded": {
"behavior": {
"singleLogout": false,
"universalLogout": false,
"globalTokenRevocation": false
}
}
}Note the clientId in the response. You need it, along with the app's id, to retrieve the client secret in the next step.
Access Gateway generates the clientSecret for your app when you create it, but doesn't return it in the create response. Retrieve it separately, then store it securely. Your client app needs both clientId and clientSecret to authenticate.
- Send a
GETrequest to the Retrieve the client secret endpoint, using the app'sidas the path parameter. - Store the returned
clientSecretsecurely. You can't retrieve the same secret value again after you rotate it.
Note: If you need to invalidate the current secret, for example, after a suspected compromise, generate a new one using the Generate a client secret endpoint. This immediately invalidates the previous secret.
curl -i -X GET \
'https://{oaghostname}/api/v2/apps/{applicationId}/credentials/secret' \
-H 'Authorization: Bearer <YOUR_JWT_HERE>'{
"clientSecret": "<generated-client-secret>"
}After you create the app in Access Gateway and retrieve its client secret, configure your client to use Access Gateway as its OIDC provider.
You must point your client app at Access Gateway, not your Okta tenant, for authentication to work. Use the OIDC discovery document to configure your client's OIDC settings. It's a JSON file that's served at /.well-known/openid-configuration on your Access Gateway authorization server. It contains all the endpoint URLs that your client needs.
- Use the Retrieve the OpenID Connect discovery document endpoint with your
idpIdas the path parameter. - In the response from the discovery document endpoint, note the endpoint URLs that are returned. See the following response example.
- Use the endpoint URLs to configure your client's OIDC settings. The document includes the following endpoints:
authorization_endpoint: Where the client sends the user to sign intoken_endpoint: Where the client exchanges an authorization code for tokensuserinfo_endpoint: Where the client retrieves claims about the signed-in userjwks_uri: Where the client retrieves Access Gateway's public keys to validate token signaturesintrospection_endpoint: Where the client checks whether a token is still validrevocation_endpoint: Where the client invalidates a token when the user signs out [[style="list-style-type:lower-alpha"]]
- Set your client's issuer to the
issuervalue from the discovery document. Your client uses this value to validate theissclaim in tokens that it receives.
Note: Access Gateway sets the
issclaim to its own authorization server domain, not your Okta tenant domain. If your client is configured to validate tokens from Okta, update the issuer to the Access Gateway domain.
{
"issuer": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac",
"authorization_endpoint": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac/protocol/openid-connect/auth",
"token_endpoint": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac/protocol/openid-connect/token",
"userinfo_endpoint": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac/protocol/openid-connect/userinfo",
"jwks_uri": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac/protocol/openid-connect/certs",
"introspection_endpoint": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac/protocol/openid-connect/token/introspect",
"revocation_endpoint": "https://oag.example.com/realms/3f63f461-c7fc-483b-b2ae-961633d251ac/protocol/openid-connect/revoke",
"scopes_supported": [
"openid",
"profile",
"email",
"offline_access"
],
"response_types_supported": [
"code"
],
"grant_types_supported": [
"authorization_code",
"refresh_token",
"client_credentials"
],
"token_endpoint_auth_methods_supported": [
"client_secret"
]
}