GuidesAuth Providers
Microsoft Auth
Add Microsoft (Entra ID) OAuth sign-in to your app.
Docs are in beta — content is improving rapidly. Found something missing? Open an issue on GitHub or reach out on Twitter (X).
1. Register an App in Microsoft Entra ID
- Go to the Azure Portal → Microsoft Entra ID → App registrations → New registration
- Fill in:
- Name — your app name
- Supported account types — choose Accounts in any organizational directory and personal Microsoft accounts for the widest reach
- Redirect URI — select Web and enter:
http://localhost:3000/api/auth/callback/microsoft(dev)https://yourdomain.com/api/auth/callback/microsoft(prod)
- Click Register
- From the Overview page, copy the Application (client) ID — this is your
MICROSOFT_CLIENT_ID - Go to Certificates & secrets → New client secret, set an expiry, and copy the Value — this is your
MICROSOFT_CLIENT_SECRET
To restrict sign-in to a single tenant, copy the Directory (tenant) ID from the Overview page and set
tenantIdinsrc/features/auth/index.tsinstead of'common'.
2. Set Environment Variables
# .env.local
MICROSOFT_CLIENT_ID=your-application-client-id
MICROSOFT_CLIENT_SECRET=your-client-secret-value3. Enable in Config
In src/appConfig.ts set:
microsoft: { enabled: true },4. Test
- Run
pnpm dev - Navigate to
/auth/sign-in - A Sign in with Microsoft button will appear
Production Checklist
- Add your production redirect URI in Authentication → Redirect URIs
- Set a calendar reminder before your client secret expires (max 24 months)
- If restricting to your organisation, update
tenantIdinsrc/features/auth/index.tsto your Directory (tenant) ID
Troubleshooting
AADSTS50011— redirect URI mismatch — the URI in Azure must exactly match/api/auth/callback/microsoft- No email returned — Entra ID does not emit the
emailclaim for managed users by default. Add it as an optional claim in the app manifest - No Microsoft button — check
MICROSOFT_CLIENT_IDandMICROSOFT_CLIENT_SECRETare set andmicrosoft.enabledistrue