Skip to content
Migrating from NextAuth.js v4? Read our migration guide.
Getting Started
Providers
Azure Ad B2c

Azure AD B2C Provider

Resources

Setup

Environment Variables

AUTH_AZURE_AD_B2C_ID
AUTH_AZURE_AD_B2C_SECRET
AUTH_AZURE_AD_B2C_ISSUER

Configuration

/auth.ts
import NextAuth from "next-auth";
import AzureADB2C from "next-auth/providers/azure-ad-b2c";
 
export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [AzureADB2C({
    clientId: AUTH_AZURE_AD_B2C_CLIENT_ID
    clientSecret: AUTH_AZURE_AD_B2C_CLIENT_SECRET
    issuer: AUTH_AZURE_AD_B2C_ISSUER
  })]
});

Tenant Setup

Basic configuration sets up Azure AD B2C to return an ID Token. This should be done as a prerequisite prior to running through the Advanced configuration. In the Tenant Setup, make sure to set the following during “User attributes and token claims”.

  • Collect attribute:
    • Email Address
    • Display Name
    • Given Name
    • Surname
  • Return claim:
    • Email Addresses
    • Display Name
    • Given Name
    • Surname
    • Identity Provider
    • Identity Provider Access Token
    • User’s Object ID
Auth.js © Balázs Orbán and Team - 2024