Configure OpenID Connect with the authorization code flow and Okta
Using the OpenID Connect plugin, set up the auth code flow to connect to an identity provider (IdP) through a browser. You must specify your Okta app client ID, client secret, and issuer URL (for example: https://domain.okta.com/oauth2/a36f045h4597
) in the OIDC plugin configuration. In addition, you must configure any scopes
from Okta as well as your redirect URI in the plugin configuration.
Prerequisites
Kong Konnect
This is a Konnect tutorial and requires a Konnect personal access token.
-
Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Export your token to an environment variable:
export KONNECT_TOKEN='YOUR_KONNECT_PAT'
Copied! -
Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN --deck-output
Copied!This sets up a Konnect Control Plane named
quickstart
, provisions a local Data Plane, and prints out the following environment variable exports:export DECK_KONNECT_TOKEN=$KONNECT_TOKEN export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='http://localhost:8000'
Copied!Copy and paste these into your terminal to configure your session.
Create an application in Okta
- In Okta, navigate to Applications > Applications in the sidebar.
- Click Create App Integration.
- Select OIDC - OpenID Connect.
- Select Web Application.
- Click Authorization Code for the grant type.
- In both the Sign-in redirect URIs and Sign-out redirect URIs fields, enter a location handled by your Route in Kong Gateway. In this tutorial, it will be your Ngrok host followed by
/anything
. For example:https://a36f045h4597.ngrok-free.app/anything
- In the Assignments section, for Controlled access, select Skip group assignment for now. We will assign the app to the test Okta user you created in the prerequisites next.
Save your configuration.
Do not select Allow everyone in your organization to access otherwise the access token won’t be verified against Okta.
-
Export the client ID and client secret of your Okta app:
export DECK_OKTA_CLIENT_ID="YOUR-OKTA-APP-CLIENT-ID" export DECK_OKTA_CLIENT_SECRET="YOUR-OKTA-APP-CLIENT-SECRET"
Copied!export DECK_OKTA_CLIENT_ID="YOUR-OKTA-APP-CLIENT-ID" export DECK_OKTA_CLIENT_SECRET="YOUR-OKTA-APP-CLIENT-SECRET"
Copied! - In the Assignment tab, assign your app to your Okta test user.
Create an authorization server and access policy
- Using your Okta credentials, log in to the Okta portal and click Security > API in the sidebar.
- Create a server named Kong API Management with an audience and description.
-
Copy the issuer URL for your authorization server, strip the
/.well-known/oauth-authorization-server
, and export it as an environment variable:export DECK_ISSUER_URL="YOUR-ISSUER-URL"
Copied!export DECK_ISSUER_URL="YOUR-ISSUER-URL"
Copied!It should be formatted like
https://domain.okta.com/oauth2/a36f045h4597
. -
On the Access Policy tab, create a new access policy and assign the Okta application you just created.
- Add a new rule and configure the following settings:
- Grant type: Authorization Code
- User is: Any user assigned the app
- Scopes requested: Any scopes
Enable the OpenID Connect plugin with the auth code flow
Set up an instance of the OpenID Connect plugin with the auth code flow and session authentication for Okta.
Enable the OpenID Connect plugin on the example-service
Service:
echo '
_format_version: "3.0"
plugins:
- name: openid-connect
service: example-service
config:
issuer: "${{ env "DECK_ISSUER_URL" }}"
client_id:
- "${{ env "DECK_OKTA_CLIENT_ID" }}"
client_secret:
- "${{ env "DECK_OKTA_CLIENT_SECRET" }}"
redirect_uri:
- "${{ env "DECK_NGROK_HOST" }}"
scopes:
- openid
- email
- profile
auth_methods:
- authorization_code
token_endpoint_auth_method: client_secret_basic
response_mode: form_post
' | deck gateway apply -
In this example:
-
issuer
,client ID
,client secret
, andclient auth
: Settings that connect the plugin to your IdP (in this case, Okta). -
auth_methods
: Specifies that the plugin should use the authorization code flow. -
response_mode
: Set toform_post
so that authorization codes don’t get logged to access logs.
Validate authorization code login
Access the Route you configured in the prerequisites. In a new browser tab, navigate to the following:
open $DECK_NGROK_HOST
The browser should be redirected to the Okta login page. You should be able to successfully log in with your Okta user account.
Cleanup
Clean up Konnect environment
If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.