Skip to content

Commit e2cfe64

Browse files
Merge pull request #339 from CodebreakerApp/copilot/fix-26d60a72-674a-40eb-b26f-2a84e4fe0c96
Add comprehensive Microsoft External ID authentication documentation
2 parents 365d781 + 63a0a01 commit e2cfe64

8 files changed

Lines changed: 2676 additions & 8 deletions

File tree

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,35 @@ TODO: this test will move to this repo
104104
* Azure Storage message queue
105105
* Azure Key Vault
106106

107-
## Configuration authentication with Azure AD B2C
107+
## Authentication Configuration
108108

109-
With AADB2C, the API connectors need to be updated after publishing the backend, by:
109+
The Codebreaker platform uses **Microsoft External ID** (formerly Azure AD B2C) for authentication across all components.
110110

111-
- setting the Endpoint URLs to https://<<gateway>>/users/api-connectors/validate-before-user-creation and https://<<gateway>>/users/api-connectors/enrich-token
112-
- setting the basic-authentication password in the gateway-keyvault with the key AADB2C-ApiConnector-Password
113-
- and setting that password in tha API connectors
111+
### Documentation
112+
113+
- **[Complete Authentication Guide](docs/authentication/microsoft-external-id.md)**: Comprehensive documentation covering Gateway, APIs, Blazor, WPF, MAUI, Uno Platform, and WinUI configuration
114+
- **[Quick Start Guide](docs/authentication/quick-start.md)**: Fast-track setup with code snippets and common patterns
115+
- **[Authentication Overview](docs/authentication/README.md)**: Architecture overview and platform support matrix
116+
117+
### Quick Setup
118+
119+
For the Gateway service with Azure AD B2C:
120+
121+
1. Configure `appsettings.json`:
122+
```json
123+
{
124+
"AzureAdB2C": {
125+
"Instance": "https://<tenant>.b2clogin.com",
126+
"Domain": "<tenant>.onmicrosoft.com",
127+
"ClientId": "<client-id>",
128+
"SignUpSignInPolicyId": "B2C_1_SUSI"
129+
}
130+
}
131+
```
132+
133+
2. The API connectors need to be updated after publishing the backend:
134+
- Set Endpoint URLs to `https://<gateway>/users/api-connectors/validate-before-user-creation` and `https://<gateway>/users/api-connectors/enrich-token`
135+
- Store the basic-authentication password in `gateway-keyvault` with the key `AADB2C-ApiConnector-Password`
136+
- Set that password in the API connectors configuration
137+
138+
For detailed configuration instructions for all platforms, see the [authentication documentation](docs/authentication/).

docs/authentication/README.md

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
# Authentication Documentation
2+
3+
This directory contains comprehensive documentation for authentication and authorization in the Codebreaker platform.
4+
5+
## Current Implementation Status
6+
7+
**The Codebreaker project is migrating to Microsoft Entra External ID** for authentication. The documentation reflects the target implementation using Entra External ID.
8+
9+
## Documentation Files
10+
11+
### [Microsoft Entra External ID Configuration Guide](./microsoft-external-id.md)**Target Implementation**
12+
13+
Comprehensive guide for the target authentication setup:
14+
- Gateway configuration with Microsoft Entra External ID
15+
- Token flow architecture between Gateway and APIs
16+
- Blazor Server and Blazor WebAssembly client configuration
17+
- Desktop client configuration (WPF, .NET MAUI, Uno Platform, WinUI)
18+
- Security best practices
19+
- Troubleshooting common issues
20+
21+
**When to use**: Reference this guide for implementing and maintaining Microsoft Entra External ID authentication.
22+
23+
### [Azure AD B2C Configuration Guide](./azure-ad-b2c.md) ⚠️ **Legacy Reference**
24+
25+
Guide for the previous authentication implementation:
26+
- Legacy Azure AD B2C configuration
27+
- Migration considerations
28+
- Comparison with Entra External ID
29+
- Deprecation timeline
30+
31+
**When to use**: Reference this guide only for migration from Azure AD B2C or understanding legacy implementations.
32+
33+
### [Quick Start Guide](./quick-start.md)
34+
35+
Fast-track guide with:
36+
- 5-minute setup instructions for Entra External ID
37+
- Common configuration patterns
38+
- Code snippets for each platform
39+
- Quick troubleshooting tips
40+
41+
**When to use**: Use this guide when you need to quickly set up authentication or find a specific code snippet.
42+
43+
### [Architecture Diagrams](./architecture-diagrams.md)
44+
45+
Visual documentation with:
46+
- High-level architecture diagrams
47+
- Authentication flow diagrams for web and desktop
48+
- Token flow through Gateway
49+
- Security boundaries visualization
50+
- Token lifecycle diagrams
51+
52+
**When to use**: Reference these diagrams to understand the system architecture and authentication flows visually.
53+
54+
## Overview
55+
56+
The Codebreaker platform uses **Microsoft Entra External ID** for identity and access management across all client applications and backend services.
57+
58+
### Architecture
59+
60+
```mermaid
61+
graph LR
62+
subgraph "Client Applications"
63+
Blazor[Blazor]
64+
WPF[WPF]
65+
MAUI[MAUI]
66+
Uno[Uno Platform]
67+
WinUI[WinUI]
68+
end
69+
70+
subgraph "Gateway Layer"
71+
Gateway[Gateway YARP<br/>• JWT Validation<br/>• Token Forwarding<br/>• Authorization<br/>• API Routing]
72+
end
73+
74+
subgraph "Backend Services"
75+
GameAPIs[Game APIs]
76+
Ranking[Ranking]
77+
Live[Live]
78+
UserService[User Service]
79+
end
80+
81+
Blazor -->|JWT Tokens| Gateway
82+
WPF -->|JWT Tokens| Gateway
83+
MAUI -->|JWT Tokens| Gateway
84+
Uno -->|JWT Tokens| Gateway
85+
WinUI -->|JWT Tokens| Gateway
86+
87+
Gateway -->|Authenticated Requests| GameAPIs
88+
Gateway -->|Authenticated Requests| Ranking
89+
Gateway -->|Authenticated Requests| Live
90+
Gateway -->|Authenticated Requests| UserService
91+
```
92+
93+
### Key Components
94+
95+
1. **Gateway (YARP Reverse Proxy)**
96+
- Entry point for all API requests
97+
- JWT token validation using Microsoft Entra External ID
98+
- Authorization policy enforcement
99+
- Token forwarding to backend services
100+
101+
2. **Backend Services**
102+
- Game APIs, Ranking, Live, User services
103+
- Can optionally validate tokens (defense in depth)
104+
- Extract user claims for business logic
105+
106+
3. **Client Applications**
107+
- Multiple platforms supported
108+
- MSAL for desktop/mobile authentication
109+
- Microsoft.Identity.Web for Blazor
110+
- Automatic token management
111+
112+
## Getting Started
113+
114+
### For New Developers
115+
116+
1. Read the [Microsoft Entra External ID Guide](./microsoft-external-id.md) for current implementation
117+
2. Use the [Quick Start Guide](./quick-start.md) for fast setup
118+
3. Configure authentication for your specific platform
119+
4. Test with the provided code snippets
120+
121+
### For Migration from Azure AD B2C
122+
123+
1. Review the [Azure AD B2C Migration Guide](./azure-ad-b2c.md)
124+
2. Understand the differences between B2C and External ID
125+
3. Update configuration endpoints and settings
126+
4. Test thoroughly before production deployment
127+
128+
## Platform Support Matrix
129+
130+
| Platform | Authentication Library | Current Status | Documentation |
131+
|----------|----------------------|----------------|---------------|
132+
| Gateway (YARP) | Microsoft.Identity.Web | ✅ Entra External ID | [Entra External ID](./microsoft-external-id.md#gateway-configuration) |
133+
| Game APIs | Microsoft.Identity.Web | ⚠️ Optional | [Entra External ID](./microsoft-external-id.md#game-apis-service-configuration) |
134+
| Blazor Server | Microsoft.Identity.Web | ✅ Supported | [Entra External ID](./microsoft-external-id.md#blazor-server-configuration) |
135+
| Blazor WASM | MSAL.js | ✅ Supported | [Entra External ID](./microsoft-external-id.md#blazor-webassembly-wasm-configuration) |
136+
| WPF | MSAL.NET | ✅ Supported | [Entra External ID](./microsoft-external-id.md#wpf-configuration) |
137+
| .NET MAUI | MSAL.NET | ✅ Supported | [Entra External ID](./microsoft-external-id.md#net-maui-configuration) |
138+
| Uno Platform | MSAL.NET | ✅ Supported | [Entra External ID](./microsoft-external-id.md#uno-platform-configuration) |
139+
| WinUI 3 | MSAL.NET | ✅ Supported | [Entra External ID](./microsoft-external-id.md#winui-3-configuration) |
140+
141+
## Configuration Overview
142+
143+
### Target Implementation (Microsoft Entra External ID)
144+
145+
All platforms require:
146+
147+
1. **Microsoft Entra External ID Tenant**: Configured with user flows
148+
2. **App Registration**: One per platform/client type
149+
3. **Redirect URIs**: Platform-specific callback URLs
150+
4. **Client ID**: Application (client) ID from app registration
151+
5. **Authority URL**: External ID tenant endpoint (*.ciamlogin.com)
152+
153+
### Environment Variables (Target)
154+
155+
Development:
156+
```bash
157+
EntraExternalId__Instance=https://your-tenant.ciamlogin.com
158+
EntraExternalId__Domain=your-tenant.onmicrosoft.com
159+
EntraExternalId__TenantId=<tenant-id>
160+
EntraExternalId__ClientId=<client-id>
161+
```
162+
163+
Production (use Azure Key Vault):
164+
```bash
165+
az keyvault secret set --vault-name gateway-keyvault \
166+
--name "EntraExternalId--ClientSecret" \
167+
--value "<secure-password>"
168+
```
169+
170+
## Common Scenarios
171+
172+
### Scenario 1: Web Application (Blazor)
173+
174+
**Use Case**: Public-facing web application with user authentication
175+
176+
**Setup**:
177+
- Blazor Server or Blazor WASM
178+
- Microsoft Entra External ID for authentication
179+
- Gateway forwards authenticated requests to APIs
180+
181+
**Documentation**: [Entra External ID Blazor Configuration](./microsoft-external-id.md#blazor-client-configuration)
182+
183+
### Scenario 2: Desktop Application (WPF/MAUI)
184+
185+
**Use Case**: Native desktop/mobile application
186+
187+
**Setup**:
188+
- MSAL.NET for authentication
189+
- Microsoft Entra External ID authority
190+
- Direct API calls through Gateway
191+
192+
**Documentation**: [Entra External ID Desktop Configuration](./microsoft-external-id.md#desktop-client-configuration)
193+
194+
### Scenario 3: Anonymous + Authenticated Users
195+
196+
**Use Case**: Game supporting both guest and registered players
197+
198+
**Setup**:
199+
- Anonymous user service for guest accounts
200+
- Optional authentication upgrade to Entra External ID
201+
- Mixed authorization policies
202+
203+
**Documentation**:
204+
- [User Service README](../../src/services/user/README.md)
205+
- [Gateway Configuration](./microsoft-external-id.md#gateway-configuration)
206+
207+
## Security Considerations
208+
209+
### Critical Security Practices
210+
211+
1. **Never commit secrets**: Use Azure Key Vault or user secrets
212+
2. **Use HTTPS in production**: HTTP only for local development
213+
3. **Validate tokens at multiple layers**: Gateway AND API services
214+
4. **Implement proper CORS**: Don't use `AllowAnyOrigin()` in production
215+
5. **Rotate secrets regularly**: Set up automated secret rotation
216+
6. **Monitor authentication**: Log and alert on suspicious activity
217+
218+
See [Entra External ID Security Guide](./microsoft-external-id.md#security-best-practices) for detailed guidance.
219+
220+
## Troubleshooting
221+
222+
### Quick Diagnostics (Target Implementation)
223+
224+
```bash
225+
# Check if Entra External ID token is valid
226+
curl -H "Authorization: Bearer <token>" https://your-gateway-url.com/games
227+
228+
# Decode JWT token
229+
# Visit https://jwt.ms and paste your token
230+
231+
# Test Entra External ID authentication endpoint
232+
curl https://your-tenant.ciamlogin.com/<tenant-id>/v2.0/.well-known/openid-configuration
233+
```
234+
235+
### Common Issues
236+
237+
1. **CORS errors**: See [Entra External ID Troubleshooting](./microsoft-external-id.md#2-cors-errors-in-browser)
238+
2. **Token validation failures**: Check Entra External ID configuration
239+
3. **Redirect URI mismatch**: Verify Entra External ID app registration
240+
4. **Authority not found**: Check tenant ID and ciamlogin.com endpoint
241+
242+
Full troubleshooting guide: [Entra External ID Troubleshooting](./microsoft-external-id.md#troubleshooting)
243+
244+
## Migration from Azure AD B2C
245+
246+
### Migration Checklist
247+
248+
If migrating from Azure AD B2C to Microsoft Entra External ID:
249+
250+
1. **Setup External ID tenant**:
251+
- Create new Entra External ID tenant
252+
- Configure user flows
253+
- Create app registrations
254+
255+
2. **Update configuration**:
256+
- Change endpoints from *.b2clogin.com to *.ciamlogin.com
257+
- Update configuration sections from AzureAdB2C to EntraExternalId
258+
- Update authority URLs to include tenant ID
259+
260+
3. **Test migration**:
261+
- Test with non-production workloads first
262+
- Validate token compatibility
263+
- Verify all client platforms
264+
265+
4. **Resources**:
266+
- [Microsoft Entra External ID Guide](./microsoft-external-id.md)
267+
- [Migration Reference](./azure-ad-b2c.md)
268+
269+
## Additional Resources
270+
271+
### Official Microsoft Documentation
272+
273+
- [Microsoft Entra External ID](https://learn.microsoft.com/en-us/entra/external-id/)**Current**
274+
- [Azure AD B2C Documentation](https://learn.microsoft.com/en-us/azure/active-directory-b2c/) ⚠️ **Legacy**
275+
- [MSAL.NET](https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-overview)
276+
- [Microsoft.Identity.Web](https://learn.microsoft.com/en-us/azure/active-directory/develop/microsoft-identity-web)
277+
278+
### Codebreaker Resources
279+
280+
- [Gateway Service](../../src/services/gateway/)**Uses Entra External ID**
281+
- [User Service](../../src/services/user/)
282+
- [Game APIs](../../src/services/gameapis/)
283+
- [Main README](../../README.md)
284+
285+
### Sample Code
286+
287+
- [Microsoft Entra External ID Samples](https://github.com/Azure-Samples?q=external-id)**Current**
288+
- [Codebreaker Backend Repository](https://github.com/CodebreakerApp/Codebreaker.Backend)
289+
290+
## Contributing
291+
292+
Found an issue or have a suggestion?
293+
294+
1. Check existing [issues](https://github.com/CodebreakerApp/Codebreaker.Backend/issues)
295+
2. Open a new issue with details
296+
3. Submit a pull request with improvements
297+
298+
## Support
299+
300+
For questions or issues:
301+
302+
- **Current implementation**: Use [Microsoft Entra External ID Guide](./microsoft-external-id.md)
303+
- **Migration questions**: See [Azure AD B2C Migration Guide](./azure-ad-b2c.md)
304+
- **Microsoft Identity issues**: See [Official Documentation](https://learn.microsoft.com/en-us/entra/external-id/)
305+
306+
## License
307+
308+
This documentation is part of the Codebreaker project. See [LICENSE](../../LICENSE) for details.

0 commit comments

Comments
 (0)