Skip to content
Migrating from NextAuth.js v4? Read our migration guide.
API reference


Built-in Azure AD integration.



  • Record<string, any>



email: string;


nickname: string;


picture: string;


sub: string;


default<P>(options): OAuthConfig<P>

Type parameters

Type parameter
P extends AzureADProfile


optionsOAuthUserConfig<P> & { profilePhotoSize: | 64 | 48 | 96 | 120 | 240 | 360 | 432 | 504 | 648; tenantId: string; }




Azure Active Directory is now known as Microsoft Entra ID. Import this provider from the providers/microsoft-entra-id submodule instead of providers/azure-ad.

Add Azure AD login to your page.


Callback URL


import Auth from "@auth/core"
import AzureAd from "@auth/core/providers/azure-ad"
const request = new Request(origin)
const response = await Auth(request, {
  providers: [AzureAd({ clientId: AZURE_AD_CLIENT_ID, clientSecret: AZURE_AD_CLIENT_SECRET })],



To allow specific Active Directory users access:

  • In search for “Azure Active Directory”, and select your organization.
  • Next, go to “App Registration” in the left menu, and create a new one.
  • Pay close attention to “Who can use this application or access this API?”
    • This allows you to scope access to specific types of user accounts
    • Only your tenant, all azure tenants, or all azure tenants and public Microsoft accounts (Skype, Xbox,, etc.)
  • When asked for a redirection URL, use or for development http://localhost:3000/api/auth/callback/azure-ad.
  • After your App Registration is created, under “Client Credential” create your Client secret.
  • Click on “API Permissions” and click “Grant admin consent for…” to allow User.Read access to your tenant.
  • Now copy your:
    • Application (client) ID
    • Directory (tenant) ID
    • Client secret (value)

In .env.local create the following entries:

AZURE_AD_CLIENT_ID=<copy Application (client) ID here>
AZURE_AD_CLIENT_SECRET=<copy generated client secret value here>
AZURE_AD_TENANT_ID=<copy the tenant id here>

That will default the tenant to use the common authorization endpoint. For more details see here.

Azure AD returns the profile picture in an ArrayBuffer, instead of just a URL to the image, so our provider converts it to a base64 encoded image string and returns that instead. See: The default image size is 48x48 to avoid running out of space in case the session is saved as a JWT.

In pages/api/auth/[...nextauth].js find or add the AzureAD entries:

import AzureADProvider from "next-auth/providers/azure-ad";
providers: [
    clientId: process.env.AZURE_AD_CLIENT_ID,
    clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
    tenantId: process.env.AZURE_AD_TENANT_ID,


By default, Auth.js assumes that the AzureAd provider is based on the OAuth 2 specification.


The AzureAd provider comes with a default configuration. To override the defaults for your use case, check out customizing a built-in OAuth provider.

Disclaimer If you think you found a bug in the default configuration, you can open an issue.

Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, we might not pursue a resolution. You can ask for more help in Discussions.

Auth.js © Balázs Orbán and Team - 2024