Login 24/7 Support Community

Dynamic Client Registration using Okta

We are going walk you through a basic integration of Tyk with Okta using the OpenID Connect Dynamic Client Registration protocol. Our current implementation provides support for the client credentials flow with support for JWT JSON Web Tokens .

The user journey is as follow:

  1. A developer signs up and creates a Dynamic Client Registration provider using the Developer Portal.

  2. Tyk sends the Dynamic Client Registration call to your IDPIdentity Provider . The IDP replies with the client ID and secret.

  3. Using that information, the developer (or the application) triggers a call to the token endpoint of the IDP.

  4. The developer (or the application) then triggers a call to Tyk, using the token that was generated by the IDP. Tyk validates this token using the JWKSJSON Web Key Sets provided by the IDP.

Requirements

Getting started with OKTA

First signup to OKTA, the initial screen looks like:

Step 1

The first thing you’ll need for our integration is an API token from OKTA, the OpenID specification also calls this an Initial Access Token to differentiate it from other tokens that are used with this protocol. To create this token, click API option from the Security menu on the navigation bar:

Step 2

From the API section, select the Tokens tab and click Create Token and enter a name for the token. For this guide we’re calling it “Tyk Integration”:

Step 3

Click Create Token. Keep it safe as you’ll use this token to configure Tyk.

Next you need to create a scope, from the Authorization servers tab in the API section, click Add Scope. You need to select the Set as default scope option:

Step 4

Setting up Tyk

Now you’re ready to set up Tyk. For compatibility reasons, check your tyk_analytics.conf and make sure that a proper oauth_redirect_uri_separator parameter is set. You may use the following value:

    "oauth_redirect_uri_separator": ";",

Remember to restart the service after applying the above change.

Now open the Tyk Dashboard and click APIs under System Management. Create a new API called “OKTA API”:

Step 5

Complete first part of the API creation form, then click Configure API and set the Authentication mode as in the image below:

Step 6

Note

Where do I get the proper JWKS URI for my Keycloak environment?

From the OKTA Dashboard, open the API section under Security, take the base URL from the default Authorization Server and append the /v1/keys suffix, e.g. https://tyk-testing.okta.com/oauth2/default/v1/keys.

For the Identity Source field use "sub" and for Policy Field Name use "pol".

  1. Click Save
  2. Select Policies under System Management
  3. Click Create a Policy and call it OKTA Policy. Use the default values for this policy.
  4. In the Access rights section, select your previously created OKTA API. You will also need to enter an expiration setting for your keys.

After the policy is created, switch back to the API settings and make sure that the API is using your OKTA Policy policy:

Step 7

Now you’re ready to add this API to the Developer Portal.

  1. Click Catalogue under Portal Management on the navigation menu.
  2. Click Add New API, enter a name for it and select the newly created policy. Again, you will use OKTA API:

Step 8

  1. Click Save then open the API added again
  2. Open the Settings tab.
  3. In API Details select the Override global settings option.

Note

Tyk lets you set global portal settings that apply to all portal-listed APIs, in this guide we assume you’re enabling and setting up DCR for a single API. In case you want to enable DCR for all the APIs, you should go to the Settings section under Portal Management, and in the API Access tab you can enter your DCR settings there.

  1. Scroll down to the DCR section and enter the following settings:

Step 9

Providers: Different providers might implement the standard in slightly different ways, Tyk provides a specific driver for each one. For IDPs that aren’t on the list use the “Other” option. For this guide, pick “OKTA”.

Grant Types: The OAuth 2.0 grant types types that will be used by the client, see the specification for more details. Set “Client Credentials”.

Token Endpoint Auth Method: defines the way the client will authenticate against the token endpoint. Use “Client Secret - Post”.

Response Types: OAuth 2.0 response types that will be used by the client. Set Token.

Identity Provider Host: Base IDP URL, e.g. https://tyk-testing.okta.com/

Client Registration Endpoint: OpenID Connect client registration endpoint. The value we use is https://tyk-testing.okta.com/oauth2/v1/clients

This value is found in your well-known discovery document as registration_endpoint. The well-known location URL is typically https://tyk-testing.okta.com/.well-known/openid-configuration (replace “tyk-testing” with your org.).

Initial Registration Access Token: the token that’s used to register new clients, this was generated in the early steps of the guide.

Note

A note on grant types and response types in OKTA

It’s important to note that OKTA’s DCR endpoint supports a parameter called "application_type", the application types aren’t standard across all IDPs, while the initial specification mentions "native" or "web" types, some IDPs implement their own. In the current implementation Tyk supports the usage of the "service" application type which is required to support the client credentials flow that’s described in this guide, this is set automatically when OKTA is set as the provider. In the future we may extend this to support additional types, you will find more information in the official OKTA documentation.

Testing the flow

Now that both Tyk and OKTA are ready we can test the complete flow.

  1. Click Developers under Portal Management
  2. Click on Add developer and create a developer user.

After the developer is created, open your Developer Portal, click on the OAuth Clients navigation bar button and follow the wizard:

Step 10

Click Create first OAuth Client. You’ll see your previously created OKTA API, select it and click Save and continue. The following screen will require you to enter a client name. It’s also possible to set redirect URLs if you also plan to use this client for other flow types. This setting can be left blank for the purposes of this guide.

Step 11

Once you click Create, Tyk will trigger a registration on your IDP and the details of your client will be displayed:

Step 12

If you check the OKTA dashboard you will see this client too:

Step 13

The next step is to generate a token and use it for accessing our OKTA API. We’ll use Postman for this. You will need your token URL which is also the well-known URL for your organisation. For this guide you’ll use https://[org].okta.com/oauth2/default/v1/token

Your Postman request should contain the following body, where "client_id" and "client_secret" are the credentials you got from the developer portal:

Step 14

Note that we aren’t using any additional header for this request, the client credentials are enough. We’re also passing our previously created "tyk" scope as value.

Once we get a response from the IDP, we can copy the "access_token" and use it to access our OKTA API, this request will be proxied by Tyk:

Step 15