Welcome to the Microsoft Identity Platform .NET Code Samples repository!
This repository provides a comprehensive set of end-to-end samples demonstrating how to integrate Microsoft Entra ID authentication and authorization into .NET applications. The samples are organized by scenario and technology, making it easy to find the right starting point for your needs.
The samples are grouped into five main categories, each corresponding to a common application scenario:
Folder | App description | Authentication libraries |
---|---|---|
1-web-apps | Interactive web applications built with ASP.NET Core (OIDC) and Blazor Server web apps with Microsoft Entra sign-in | Microsoft.Identity.Web MSAL.NET |
2-web-apis | Protected Web APIs, Azure Function APIs and APIs for On-Behalf-Of (OBO) flows | Microsoft.Identity.Web MSAL.NET |
3-client-spa | Blazor WebAssembly SPA authentication | Microsoft.Authentication.WebAssembly.Msal MSAL.NET |
4-desktop-apps | WinForms, WPF, WinUI interactive authentication apps, console device code/daemon apps and .NET MAUI cross-platform apps | MSAL.NET |
5-migration | AD FS to Microsoft Entra ste-by-step migration guide | Microsoft.Identity.Web MSAL.NET |
6-advanced | Access the logged-in user's token cache from background apps, APIs and services | Microsoft.Identity.Web MSAL.NET |
Each folder contains one or more samples, each with its own README and instructions.
- Browse the folders above to find the app type/scenario that matches your use case.
- Read the sample’s README.md for prerequisites, setup instructions, and code walkthroughs.
- Clone and run the sample following the provided steps.
All samples are built with the latest supported .NET versions and Microsoft.Identity libraries.
- Configuration is managed via appsettings.json and environment variables.
- Secrets and credentials should never be committed to source control or exposed in GitHub. Ensure that you keep your credentials and details safe when using the material in these samples. Use Azure Key Vault or environment variables for sensitive data.
We welcome contributions!
Please see CONTRIBUTING.md for guidelines on submitting new samples or improvements.
- For questions, open an issue.
- For Microsoft identity platform documentation, visit learn.microsoft.com/entra/identity-platform.
This project is licensed under the MIT License.
- Documentation on learn.microsoft.com
- Authentication library source code on GitHub
Happy coding!