|
| 1 | +# MSAL.NET Guidelines |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Microsoft Authentication Library (MSAL) for .NET is a highly scalable authentication library that enables applications to authenticate with the Microsoft identity platform. For confidential client scenarios (server-side applications), the library provides: |
| 6 | + |
| 7 | +- Token acquisition for service-to-service calls |
| 8 | +- Flexible token caching with distributed cache support |
| 9 | +- Managed identity integration for Azure workloads |
| 10 | +- On-behalf-of flow for service-to-service delegated access |
| 11 | + |
| 12 | +Through its comprehensive feature set and proven reliability, MSAL.NET simplifies the implementation of secure authentication in server-side applications while maintaining optimal performance and security. |
| 13 | + |
| 14 | +## Repository Structure |
| 15 | + |
| 16 | +### Core Directories |
| 17 | +- `/src/client/Microsoft.Identity.Client` - Core MSAL functionality |
| 18 | + - `ConfidentialClientApplication.cs` - Primary confidential client implementation |
| 19 | + - `ApiConfig/` - API configuration and builders |
| 20 | + - `Cache/` - Token cache implementations |
| 21 | + - `ManagedIdentity/` - Azure managed identity support |
| 22 | + - `OAuth2/` - OAuth protocol implementations |
| 23 | + - `Internal/` - Internal components and utilities |
| 24 | +- `/tests` - Unit tests and integration tests |
| 25 | +- `/benchmark` - Performance benchmarking infrastructure |
| 26 | +- `/tools` - Development and configuration tools |
| 27 | + |
| 28 | +## Core Components |
| 29 | + |
| 30 | +### Confidential Client Features |
| 31 | +- Microsoft.Identity.Client - Main MSAL library with confidential client support |
| 32 | +- Token cache implementations with extensible serialization |
| 33 | +- Managed identity integration for Azure environments |
| 34 | + |
| 35 | +### Authentication Components |
| 36 | +- IConfidentialClientApplication - Primary interface for confidential clients |
| 37 | +- Token cache providers and serialization extensibility |
| 38 | +- Client credential builders and configurations |
| 39 | +- Custom assertion providers (certificates, managed identity) |
| 40 | + |
| 41 | +## Development Guidelines |
| 42 | + |
| 43 | +### Core Development Principles |
| 44 | +- Follow .editorconfig rules strictly |
| 45 | +- Maintain backward compatibility due to widespread usage |
| 46 | +- Implement proper error handling and retry logic |
| 47 | +- Keep dependencies minimal and well-justified |
| 48 | +- Document security considerations thoroughly |
| 49 | + |
| 50 | +### Authentication Best Practices |
| 51 | +- Use certificate-based authentication over client secrets when possible |
| 52 | +- Implement token caching for optimal performance |
| 53 | +- Handle token expiration and refresh scenarios |
| 54 | +- Configure appropriate token lifetimes |
| 55 | +- Use managed identities in Azure environments when available |
| 56 | + |
| 57 | +### Performance Requirements |
| 58 | +- Implement distributed token caching for scale-out scenarios |
| 59 | +- Optimize token acquisition patterns |
| 60 | +- Use asynchronous APIs consistently |
| 61 | +- Configure appropriate retry policies |
| 62 | +- Benchmark token operations in high-throughput scenarios |
| 63 | + |
| 64 | +### Security Guidelines |
| 65 | +- Secure storage of client secrets and certificates |
| 66 | +- Implement proper token validation |
| 67 | +- Follow least-privilege principle for scopes |
| 68 | +- Handle sensitive data appropriately |
| 69 | +- Implement proper logging (avoiding sensitive data) |
| 70 | + |
| 71 | +### Testing Requirements |
| 72 | +- Maintain comprehensive test coverage |
| 73 | +- Include integration tests with actual identity endpoints |
| 74 | +- Test token cache implementations thoroughly |
| 75 | +- Verify managed identity scenarios |
| 76 | +- Include performance benchmarks for token operations |
| 77 | + |
| 78 | +### Public API Changes |
| 79 | +- The project uses Microsoft.CodeAnalysis.PublicApiAnalyzers |
| 80 | +- For any public API changes: |
| 81 | + 1. Update PublicAPI.Unshipped.txt in the package directory |
| 82 | + 2. Include complete API signatures |
| 83 | + 3. Consider backward compatibility impacts |
| 84 | + 4. Document breaking changes clearly |
| 85 | + |
| 86 | +Example format: |
| 87 | +```diff |
| 88 | +// Adding new API |
| 89 | ++Microsoft.Identity.Client.ConfidentialClientApplication.AcquireTokenForClient() -> Task<AuthenticationResult> |
| 90 | ++Microsoft.Identity.Client.IConfidentialClientApplication.GetAccounts() -> Task<IEnumerable<IAccount>> |
| 91 | + |
| 92 | +// Removing API (requires careful consideration) |
| 93 | +-Microsoft.Identity.Client.ConfidentialClientApplication.ObsoleteMethod() -> void |
| 94 | +``` |
| 95 | + |
| 96 | +The analyzer enforces documentation of all public API changes in PublicAPI.Unshipped.txt and will fail the build if changes are not properly reflected. |
0 commit comments