curl -X POST "https://us.api.konghq.com/v3/portals" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"name": "MyDevPortal",
"authentication_enabled": true,
"auto_approve_applications": true,
"auto_approve_developers": true,
"default_api_visibility": "public",
"default_page_visibility": "public"
}'Automatically create and manage Dev Portal applications in Azure AD with Dynamic Client Registration
You can use Dynamic Client Registration to automatically create Dev Portal applications in Azure AD. First, create an application in Azure and configure the Application.ReadWrite.OwnedBy and User.Read API permissions, select Accounts in this organizational directory only for the supported account types, and create a client secret. Then, create a new DCR provider in your Dev Portal settings and create a new auth strategy for DCR.
Prerequisites
Kong Konnect
If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.
- The following Konnect items are required to complete this tutorial:
- Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Set the personal access token as an environment variable:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Kong Konnect roles
To use this tutorial, you need the following Kong Konnect roles:
- Portal Creator
- API Creator
- DCR Provider Creator
- API Publisher
- API Registration Approver (if applications aren’t auto-approved in your Dev Portal)
Configure a Dev Portal and an API
-
Export your Dev Portal ID and URL from the response:
export PORTAL_ID='YOUR-DEV-PORTAL-ID' export PORTAL_URL='YOUR-DEV-PORTAL-DOMAIN' -
Create a page so the portal is accessible and published APIs are visible:
curl -X POST "https://us.api.konghq.com/v3/portals/$PORTAL_ID/pages" \ --no-progress-meter --fail-with-body \ -H "Authorization: Bearer $KONNECT_TOKEN" \ --json '{ "title": "My Page", "slug": "/", "visibility": "public", "status": "published", "content": "# Welcome to My Dev Portal\nExplore the available APIs below:\n::apis-list\n---\npersist-page-number: true\ncta-text: \"View APIs\"\n---\n" }' -
curl -X POST "https://us.api.konghq.com/v3/apis" \ --no-progress-meter --fail-with-body \ -H "Authorization: Bearer $KONNECT_TOKEN" \ --json '{ "name": "MyAPI" }'Export the ID of your API from the response:
export API_ID='YOUR-API-ID' -
Publish the API to your Dev Portal:
curl -X PUT "https://us.api.konghq.com/v3/apis/$API_ID/publications/$PORTAL_ID" \ --no-progress-meter --fail-with-body \ -H "Authorization: Bearer $KONNECT_TOKEN" \ --json '{ "visibility": "public" }'
Register a Dev Portal developer account
Register a test developer account with your Dev Portal by navigating to your Dev Portal and clicking Sign up:
open https://$PORTAL_URL/For the purpose of this tutorial, we’ve set our Dev Portal to automatically approve developer registrations.
Azure AD
You’ll need an Azure AD account for this tutorial.
Note: Dynamic client registration supports Azure OAuth v1 token endpoints only. v2 is not supported.
Configure Azure
In Azure, create the main application:
-
In Azure Active Directory, click App registrations and then click New registration.
- Enter a name for the application.
-
Ensure Single tenant only is selected for Supported account types.
-
Click Register.
-
On the application view, go to Manage > API permissions and click Add a permission.
-
Click Microsoft Graph.
- Select the following permissions:
- User.Read under Delegated permissions
- Application.ReadWrite.OwnedBy under Application permissions
-
Click Add permissions.
-
Once added, click Grant admin consent. An administrator with Global Admin rights is required for this step.
-
Select Certificates & secrets and then create a client secret and save it in a secure location. You can only view the secret once.
-
In the Overview view, copy your Directory (tenant) ID and Application (client) ID, then export them:
export TENANT_ID='YOUR-AZURE-TENANT-ID' export CLIENT_ID='YOUR-AZURE-CLIENT-ID' export CLIENT_SECRET='YOUR-AZURE-CLIENT-SECRET' export ISSUER_URL="https://sts.windows.net/$TENANT_ID"
Configure the Dev Portal
After configuring Azure, you can integrate it with the Dev Portal for Dynamic Client Registration (DCR). This process involves two main steps: first, creating the DCR provider, and second, establishing the authentication strategy. DCR providers are designed to be reusable configurations. This means once you’ve configured the Azure DCR provider, it can be used across multiple authentication strategies without needing to be set up again.
-
Create a DCR provider using the
/v2/dcr-providersendpoint:curl -X POST "https://us.api.konghq.com/v2/dcr-providers" \ --no-progress-meter --fail-with-body \ -H "Authorization: Bearer $KONNECT_TOKEN" \ --json '{ "name": "Azure DCR Provider", "provider_type": "azureAd", "issuer": "'$ISSUER_URL'", "dcr_config": { "initial_client_id": "'$CLIENT_ID'", "initial_client_secret": "'$CLIENT_SECRET'" } }' -
Export the DCR provider ID from the response:
export DCR_PROVIDER_ID='YOUR-DCR-PROVIDER-ID' -
Create an authentication strategy using the
/v2/application-auth-strategiesendpoint:curl -X POST "https://us.api.konghq.com/v2/application-auth-strategies" \ --no-progress-meter --fail-with-body \ -H "Authorization: Bearer $KONNECT_TOKEN" \ --json '{ "name": "Azure DCR Auth Strategy", "display_name": "Azure DCR Auth Strategy", "strategy_type": "openid_connect", "configs": { "openid-connect": { "issuer": "'$ISSUER_URL'", "credential_claim": [ "appid" ], "scopes": [ "openid" ], "auth_methods": [ "client_credentials", "bearer", "session" ] } }, "dcr_provider_id": "'$DCR_PROVIDER_ID'" }' -
Export the auth strategy ID from the response:
export AUTH_STRATEGY_ID='YOUR-AUTH-STRATEGY-ID'
Apply the Azure DCR auth strategy to an API
Now that the application auth strategy is configured, you can apply it to an API using the /v3/apis/{apiId}/publications/{portalId} endpoint:
curl -X PUT "https://us.api.konghq.com/v3/apis/$API_ID/publications/$PORTAL_ID" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"visibility": "public",
"auth_strategy_ids": [
"'$AUTH_STRATEGY_ID'"
]
}'Validate
Now that DCR is configured, you can create an application with Dynamic Client Registration by using a developer account.
-
Navigate to your Dev Portal URL and log in with your developer account.
-
Select an API and click Use this API.
-
Complete the Create New Application modal with your application name, authentication strategy, and description.
-
After the application is created, the Client ID and Client Secret will be displayed.
Make sure to store these values, as they will only be shown once. -
After the application is created, it will appear in your IdP. From your IdP organization, select Applications from the sidebar. You will see the application created in the Dev Portal, along with its corresponding Client ID.
For developers to authorize requests, they must attach the client ID and secret pair obtained previously in the header. They can do this by using any API client, such as Insomnia, or directly using the command line:
curl "$KONNECT_PROXY_URL/$ROUTE_PATH" \
--no-progress-meter --fail-with-body \
-H "Authorization: Basic $CLIENT_ID:$CLIENT_SECRET" \
-H "Content-Type: application/json"You can also request a bearer token from Azure using the following command, targeting the OAuth 2.0 v1 token endpoint:
curl --request GET \
--url https://login.microsoftonline.com/TENANT_ID/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=CLIENT_ID \
--data 'scope=https://graph.microsoft.com/.default' \
--data 'client_secret=CLIENT_SECRET'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.
FAQs
Can developers rotate their Entra DCR credentials?
Yes, developers can create multiple Entra DCR credentials and revoke old ones as needed. See Managing credentials for more information.