You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable Government Cloud Authentication - Allow Azure Government (GCC-High/DoD) tenants to authenticate with NextAuth.js using correct sovereign cloud endpoints (login.microsoftonline.us) without manual configuration.
Simplify Configuration - Reduce sovereign cloud setup from 15+ lines of manual endpoint overrides to a single cloud: "usgov" option, making it accessible to developers unfamiliar with Azure Government infrastructure.
Maintain Backward Compatibility - Add this feature with zero breaking changes by defaulting to public cloud ("public"), ensuring existing Azure AD users are unaffected.
Non-Goals
Graph API Integration Beyond OIDC - This PR focuses on OIDC authentication only. Advanced Microsoft Graph API features (like profile enrichment beyond ID token claims) remain user-implemented. Users can still call Graph APIs manually with obtained tokens.
China Sovereign Cloud (Initial Release) - Azure China (login.partner.microsoftonline.cn) has different requirements and less demand. We can add cloud: "china" in a follow-up PR if needed, but it's out of scope for the initial implementation.
Custom Authority Hosts - This PR uses a type-safe enum ("public" | "usgov" | "dod") to prevent misconfiguration and security issues. Users needing completely custom authority hosts can continue using manual issuer/wellKnown overrides, which remain fully supported.
Background
Why This Is Needed
Azure Government is a separate infrastructure from Azure Commercial:
Different URLs:login.microsoftonline.us vs login.microsoftonline.com
Network Isolation: Gov clouds are physically and logically isolated for compliance (FedRAMP, DoD IL4/IL5)
10,000+ Organizations: Includes federal agencies, state/local governments, and contractors serving them
This is a low-risk, high-impact addition that enables a significant user segment while maintaining NextAuth.js's quality standards.
Questions for Maintainers
API Design: Does the cloud enum approach fit NextAuth.js conventions? (Alternative: authorityHost string with validation)
Scope: Should we include Azure China support in initial release? (Can add cloud: "china" enum value, mark as experimental)
Documentation: Prefer new "Sovereign Clouds" page or section within existing Azure AD provider docs?
Testing: Any specific Gov-cloud scenarios you'd like covered beyond standard OIDC flow?
Proposal
## Summary
I would like to add support for Microsoft Azure Government clouds (GCC-High, DoD) to the Azure AD provider. This will enable 10,000+ government organizations to use NextAuth.js without manual endpoint configuration.
## Problem
The current Azure AD provider assumes Microsoft Public Cloud (`login.microsoftonline.com`). U.S. Government tenants operate in sovereign clouds with different infrastructure:
-**Authority:**`login.microsoftonline.us` (not `.com`)
-**Graph API:**`graph.microsoft.us` or `dod-graph.microsoft.us`-**Claims:** Often use `upn` instead of `email`
Today, users must manually configure 15+ lines of endpoint overrides and custom profile mapping.
## Proposed Solution
Add a `cloud` option to `AzureADProvider`:
```typescriptAzureADProvider({
clientId: process.env.AZURE_AD_CLIENT_ID,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET,
tenantId: process.env.AZURE_AD_TENANT_ID,
cloud: "usgov", // NEW: "public" | "usgov" | "dod"
})
Key Features
Cloud Endpoints:
Cloud
Authority
Graph API
"public" (default)
login.microsoftonline.com
graph.microsoft.com
"usgov" (GCC-High)
login.microsoftonline.us
graph.microsoft.us
"dod" (DoD IL5)
login.microsoftonline.us
dod-graph.microsoft.us
Benefits:
Zero breaking changes (defaults to "public")
Type-safe enum prevents misconfiguration
Auto-derives endpoints based on cloud
Robust profile mapping with Gov-cloud fallbacks
Manual overrides still respected
Prior Art
This design is based on a production-tested library I built for GCC-High authentication:
135 unit tests
Deployed in Azure GCC-High
Proven endpoint derivation patterns
Implementation Plan
I have prepared:
✅ Complete reference implementation
✅ Comprehensive test suite (20+ tests)
✅ User documentation
✅ Working example app (Next.js 15)
✅ Technical specification
Questions for Maintainers
Does this approach fit NextAuth.js architecture?
Any concerns about adding the cloud option?
Should I include China cloud support in the initial implementation?
Preference on documentation structure (new page vs section)?
Impact
Enables 10,000+ Azure Government organizations
Reduces config complexity (15 lines → 3 lines)
Maintains backward compatibility
Type-safe, secure, well-tested
I'm ready to implement this after getting maintainer feedback. Thank you for considering this contribution!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Enable Government Cloud Authentication - Allow Azure Government (GCC-High/DoD) tenants to authenticate with NextAuth.js using correct sovereign cloud endpoints (
login.microsoftonline.us) without manual configuration.Simplify Configuration - Reduce sovereign cloud setup from 15+ lines of manual endpoint overrides to a single
cloud: "usgov"option, making it accessible to developers unfamiliar with Azure Government infrastructure.Maintain Backward Compatibility - Add this feature with zero breaking changes by defaulting to public cloud (
"public"), ensuring existing Azure AD users are unaffected.Non-Goals
Graph API Integration Beyond OIDC - This PR focuses on OIDC authentication only. Advanced Microsoft Graph API features (like profile enrichment beyond ID token claims) remain user-implemented. Users can still call Graph APIs manually with obtained tokens.
China Sovereign Cloud (Initial Release) - Azure China (
login.partner.microsoftonline.cn) has different requirements and less demand. We can addcloud: "china"in a follow-up PR if needed, but it's out of scope for the initial implementation.Custom Authority Hosts - This PR uses a type-safe enum (
"public" | "usgov" | "dod") to prevent misconfiguration and security issues. Users needing completely custom authority hosts can continue using manualissuer/wellKnownoverrides, which remain fully supported.Background
Why This Is Needed
Azure Government is a separate infrastructure from Azure Commercial:
login.microsoftonline.usvslogin.microsoftonline.comCurrent Pain Points:
issuer,wellKnown,authorization,token,userinfo)email, useupninstead)Current Alternatives (All Suboptimal)
Alternative 1: Manual Endpoint Override (Status Quo)
Problems:
/v2.0, etc.)Alternative 2: Custom Provider Wrapper
Users create their own provider wrapper around Azure AD:
Problems:
Alternative 3: Use a Different Library
Switch to MSAL, Passport, or custom OIDC implementation.
Problems:
Prior Art
This PR is based on a production library I built:
oid,upn,preferred_username)Key Learnings from
latch:oidis more stable thansubfor user identity across tenantsemailclaim - must fall back toupnSimilar Features in Other Ecosystems:
azureCloudInstanceenum (AzurePublic,AzureUsGovernment,AzureGermany,AzureChina)identityMetadataURL for different cloudsregionparameter for different AWS cloudsWhy Now?
What Success Looks Like
Before:
After:
Impact:
Implementation Confidence
I have prepared:
This is a low-risk, high-impact addition that enables a significant user segment while maintaining NextAuth.js's quality standards.
Questions for Maintainers
API Design: Does the
cloudenum approach fit NextAuth.js conventions? (Alternative:authorityHoststring with validation)Scope: Should we include Azure China support in initial release? (Can add
cloud: "china"enum value, mark as experimental)Documentation: Prefer new "Sovereign Clouds" page or section within existing Azure AD provider docs?
Testing: Any specific Gov-cloud scenarios you'd like covered beyond standard OIDC flow?
Proposal
Key Features
Cloud Endpoints:
"public"(default)"usgov"(GCC-High)"dod"(DoD IL5)Benefits:
"public")Prior Art
This design is based on a production-tested library I built for GCC-High authentication:
Implementation Plan
I have prepared:
Questions for Maintainers
cloudoption?Impact
I'm ready to implement this after getting maintainer feedback. Thank you for considering this contribution!
Beta Was this translation helpful? Give feedback.
All reactions