šŸ“„ next-auth/v3/providers/azure-ad-b2c

File: azure-ad-b2c.md | Updated: 11/15/2025

Source: https://next-auth.js.org/v3/providers/azure-ad-b2c

Skip to main content

šŸŽ‰ NextAuth.js is now part of Better Auth !

This is documentation for NextAuth.js v3, which is no longer actively maintained.

For up-to-date documentation, see the **latest version ** (v4).

Version: v3

On this page

Documentation​


https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow

Configuration​


https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-create-tenant

Options​


The Azure Active Directory Provider comes with a set of default options:

You can override any of the options to suit your own use case.

Example​


  • In https://portal.azure.com/ -> Azure Active Directory create a new App Registration.
  • Make sure to remember / copy
    • Application (client) ID
    • Directory (tenant) ID
  • When asked for a redirection URL, use http://localhost:3000/api/auth/callback/azure-ad-b2c
  • Create a new secret and remember / copy its value immediately, it will disappear.

In .env.local create the following entries:

AZURE_CLIENT_ID=<copy Application (client) ID here>AZURE_CLIENT_SECRET=<copy generated secret value here>AZURE_TENANT_ID=<copy the tenant id here>

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

import Providers from 'next-auth/providers';...providers: [  Providers.AzureADB2C({    clientId: process.env.AZURE_CLIENT_ID,    clientSecret: process.env.AZURE_CLIENT_SECRET,    scope: 'offline_access User.Read',    tenantId: process.env.AZURE_TENANT_ID,  }),]...