Get credentials
1
Register an application
Go to the Azure Portal and navigate to Microsoft Entra ID > App registrations > New registration.- Name: your app name
- Supported account types: choose based on your needs (see below)
- Redirect URI: Web,
https://auth.example.com/auth/oauth/callback/microsoft
2
Create a client secret
Navigate to Certificates and secrets > New client secret. Set an expiry and copy the secret value immediately.3
Copy the Application ID
From the app overview, copy the Application (client) ID and the Directory (tenant) ID.Configuration
- Personal + work accounts
- Work accounts only (single tenant)
lib/theauth.ts
Account types and tenant
createMicrosoftProvider always uses the common authority (https://login.microsoftonline.com/common/oauth2/v2.0/...). The segment in the endpoint URLs decides who can sign in, which you can control with the generic factory shown above:
Scopes
Default scopes:openid profile email User.Read. Scopes you pass are added on top of the defaults.
User data returned
The profile photo is not fetched. Graph serves it from a separate
/me/photo/$value call that you would make yourself with the user’s access token.Related
OAuth overview
Generic OAuth 2.0 setup and account linking behavior.
SSO
SAML 2.0 and OIDC enterprise SSO, including Azure AD.
Sign in with Google for personal and workspace accounts.
Authentication overview
All sign-in methods available in theAuth.