OpenID Connect with Azure AD

Authenticate browser clients using an Azure AD identity provider.

The following configuration example allows users to authenticate and access the upstream service even though no Consumer was created for them. This means any user with a valid account in the directory will have access. If you want to restrict access further, you have several options:

  • Domain restrictions: Azure AD doesn’t provide identity tokens with the hd claim, so the OIDC plugin’s domains configuration can’t restrict users based on their domain. Using a single-tenant application will restrict access to users in your directory only. Multi-tenant apps allow users with Microsoft accounts from other directories and optionally any Microsoft account (for example live.com or Xbox accounts) to sign in.
  • Consumer mapping: If you need to interact with other Kong Gateway plugins using consumer information, you can map account data received from the IdP to a Kong Gateway Consumer. See OIDC with Consumer authorization.
  • Pseudo-Consumer mapping: For plugins that typically require Consumers, the OIDC plugin can provide a Consumer ID based on the value of a claim without mapping to an actual Consumer. Setting credential_claim to a claim in your plugin configuration extracts the value of that claim and uses it where Kong Gateway would normally use a Consumer ID. Similarly, setting authenticated_groups_claim extracts that claim’s value and uses it as a group for the ACL plugin.

Note: Azure AD provides two interfaces for its OAuth2/OIDC-related endpoints: v1.0 and v2.0. Support for some legacy v1.0 behavior is still available on v2.0, including use of v1.0 tokens by default, which is not compatible with Kong Gateway’s OIDC implementation. To force Azure AD to use v2.0 tokens, edit your application manifest and set accessTokenAcceptedVersion to 2 and include a CLIENT_ID/.default scope in your plugin configuration (see example).

Prerequisites

Environment variables

  • ISSUER: The issuer authentication URL for your IdP. For Azure AD, that typically looks like this: https://login.microsoftonline.com/$DIRECTORY/v2.0/.well-known/openid-configuration. You can find this URL by clicking Endpoints on your app registration’s Overview page.

  • CLIENT_ID: The client ID that the plugin uses when it calls authenticated endpoints of the IdP, shown on your Azure AD app registration’s Overview page.

  • CLIENT_SECRET: The URL-encoded representation of the secret you created in the Azure AD Certificates & Secrets section.

  • REDIRECT_URI: The URI you specified when configuring your app. If you didn’t add one initially, you can add a redirect URI via the Authentication section of the app settings.

Set up the plugin

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!