languages | page_type | name | description | products | urlFragment | ||||
---|---|---|---|---|---|---|---|---|---|
|
sample |
ASP.NET Core 6.0 Web App Sign-in user |
This is a ASP.NET Core 6.0 Web App that sign-in users. The code in this sample is used by one or more articles on docs.microsoft.com. |
|
ms-identity-docs-code-csharp-sign-in |
This web app, built with ASP.NET Core 6.0 Razor, has added sign-in features. It uses the Open Id Connect and ASP.NET Core Identity for authentication. This allows users to sign in with their Microsoft Entra ID accounts. Once signed in, the app can access protected resources on the user’s behalf.
-
For a quickstart experience that gets you started fast, see Quickstart: Sign in users and call the Microsoft Graph API from an ASP.NET Core web app.
-
For a in-depth tutorial that walks you through this sample from start to finish, see Tutorial: Sign in users and call the Microsoft Graph API from an ASP.NET Core web app.
- An Azure account with an active subscription. If you don't already have one, Create an account for free.
- .NET SDK
First, complete the steps in Register an application with the Microsoft identity platform to register a web application in the Microsoft identity platform.
Use the following settings for your app registration:
App registration setting |
Value for this sample app | Notes |
---|---|---|
Name | identity-client-web-app |
Suggested value for this sample. You can change the app name at any time. |
Supported account types | My organization only | Required for this sample. Support for the Single tenant. |
Platform type | Web |
Required value for this sample. Enables the required and optional settings for the app type. |
Redirect URIs | https://localhost:5001/signin-oidc |
Required value for this sample. |
Front-channel logout URL | https://localhost:5001/signout-oidc |
Required value for this sample. |
CertificateThumbprint | Value shown in Microsoft Entra admin center | Required value for this sample. |
ℹ️ Bold text in the table matches (or is similar to) a UI element in the Microsoft Entra admin center, while
code formatting
indicates a value you enter into a text box or select in the Microsoft Entra admin center.
-
Open the ~/sign-in-webapp/WebApp.csrpoj in your code editor.
-
Open the appsettings.json file and modify the following code:
"Instance": "https://login.microsoftonline.com/", "TenantId": "Enter the tenant ID obtained from the Microsoft Entra Admin Center", "ClientId": "Enter the client ID obtained from the Microsoft Entra Admin Center", "ClientCertificates": [ { "SourceType": "StoreWithThumbprint", "CertificateStorePath": "CurrentUser/My", "CertificateThumbprint": "Enter the certificate thumbprint obtained the Microsoft Entra Admin Center" } ],
-
Execute the following command to get the app up and running:
dotnet run
- Once the web app is listening, navigate to https://localhost:5001
- Sign-in with your user credentials.
- Select Sign out
The ASP.NET Core 6.0 Web App will allow users to sign-in, so it can retrieve a Security Token scoped specifically for the Microsoft Graph API, and will use that token to access the user's information. For more information about the proposed scenario, please take a look at the following diagram:
🔗 For more information about how to proctect your projects, please let's take a look at https://docs.microsoft.com/en-us/azure/active-directory/develop/sample-v2-code. To know more about how this sample has been generated, please visit https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/?view=aspnetcore-6.0
If you can't get the sample working, you've checked Stack Overflow, and you've already searched the issues in this sample's repository, open an issue report the problem.
- Search the GitHub issues in the repository - your problem might already have been reported or have an answer.
- Nothing similar? Open an issue that clearly explains the problem you're having running the sample app.
⚠️ WARNING: Any issue not limited to running this or another sample app will be closed without being addressed.
For all other requests, see Support and help options for developers | Microsoft identity platform.
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.