Microsoft sign-in
Add Microsoft account authentication to an Auth.js application.
Auth.js · Const
MicrosoftEntraID is Auth.js’s built-in OpenID Connect provider for Microsoft Entra ID. Configure client credentials and optionally an issuer to restrict authentication to a specific tenant.
MicrosoftEntraID is Auth.js’s built-in OpenID Connect provider for Microsoft Entra ID. Configure it with an application client ID and secret; supplying a tenant issuer restricts sign-in to that organization, while the default issuer permits personal, school, or work Microsoft accounts.
function default(config): OIDCConfig<MicrosoftEntraIDProfile>| Name | Type | Description |
|---|---|---|
config | OIDCUserConfig<MicrosoftEntraIDProfile> | Provider configuration containing the client credentials and optional issuer. |
OIDCConfig<MicrosoftEntraIDProfile>
import NextAuth from "next-auth"
import MicrosoftEntraID from "next-auth/providers/microsoft-entra-id"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [
MicrosoftEntraID({
clientId: process.env.AUTH_MICROSOFT_ENTRA_ID_ID,
clientSecret: process.env.AUTH_MICROSOFT_ENTRA_ID_SECRET,
issuer: process.env.AUTH_MICROSOFT_ENTRA_ID_ISSUER,
}),
],
})Registers Microsoft Entra ID with client credentials and an optional tenant-specific issuer.
Add Microsoft account authentication to an Auth.js application.
Permit only users from one Microsoft Entra organization.
Support personal, school, and work Microsoft accounts through the common endpoint.
MicrosoftEntraID configures Auth.js as an OpenID Connect provider. The essential application credentials are the client ID and client secret; an issuer can also be supplied.
Follow-up: How would you restrict access to one organization? Set issuer to the tenant-specific Microsoft login URL containing the Directory (tenant) ID.
Without an issuer, Auth.js defaults to the common v2.0 endpoint. That endpoint allows Microsoft personal, school, and work accounts to authenticate.
Follow-up: What changes for single-tenant authentication? Provide the organization’s Directory (tenant) ID in the issuer URL.
The callback path is /api/auth/callback/microsoft-entra-id, and it must be registered as the application’s callback URI. The environment variables hold the client ID, secret, and optional issuer.
Follow-up: Which provider identifier determines the callback path? The provider’s identifier is microsoft-entra-id.
MicrosoftEntraIDProfileOIDCConfigOIDCUserConfigmicrosoft-entra-id