title | description | author | manager | ms.author | ms.service | ms.subservice | ms.topic | ms.date | ms.custom |
---|---|---|---|---|---|---|---|---|---|
Sign in users to a sample ASP.NET Core web application |
Learn how to configure a sample ASP.NET Core web app to sign in and sign out users by using an external tenant. |
cilwerner |
celestedg |
cwerner |
entra-external-id |
customers |
sample |
04/23/2024 |
developer, devx-track-dotnet |
This how-to guide uses a sample ASP.NET Core web application to show the fundamentals of modern authentication using the Microsoft Authentication Library for .NET and Microsoft Identity Web for ASP.NET Core to handle authentication.
In this article, you'll register a web application in the Microsoft Entra admin center and create a sign in and sign out user flow. You'll associate your web application with the user flow, download and update a sample ASP.NET Core web application using your own external tenant details. Finally, you'll run and test the sample web application.
- Although any IDE that supports ASP.NET Core applications can be used, Visual Studio Code is used for this guide. It can be downloaded from the Downloads page.
- .NET 7.0 SDK.
- An external tenant. If you don't already have one, sign up for a free trial.
[!INCLUDE active-directory-b2c-register-app]
[!INCLUDE ciam-redirect-url-dotnet]
[!INCLUDE ciam-enable-implicit-flow]
[!INCLUDE ciam-add-client-secret]
[!INCLUDE ciam-grant-delegated-permissions]
[!INCLUDE ciam-app-integration-add-user-flow]
[!INCLUDE ciam-integration-add-user-flow]
To obtain the sample application, you can either clone it from GitHub or download it as a .zip file.
-
To clone the sample, open a command prompt and navigate to where you wish to create the project, and enter the following command:
git clone https://github.com/Azure-Samples/ms-identity-ciam-dotnet-tutorial.git
-
Download the .zip file. Extract it to a file path where the length of the name is fewer than 260 characters.
-
Navigate to the root folder of the sample you have downloaded and directory that contains the ASP.NET Core sample app:
cd 1-Authentication\1-sign-in-aspnet-core-mvc
-
Open the appsettings.json file.
-
In Authority, find
Enter_the_Tenant_Subdomain_Here
and replace it with the subdomain of your tenant. For example, if your tenant primary domain is caseyjensen@onmicrosoft.com, the value you should enter is casyjensen. -
Find the
Enter_the_Application_Id_Here
value and replace it with the application ID (clientId) of the app you registered in the Microsoft Entra admin center. -
Replace
Enter_the_Client_Secret_Here
with the client secret value you set up in Add app client secret.
-
From your shell or command line, execute the following commands:
dotnet run
-
Open your web browser and navigate to
https://localhost:7274
. -
Sign-in with an account registered to the external tenant.
-
Once signed in the display name is shown next to the Sign out button as shown in the following screenshot.
:::image type="content" source="media/tutorial-web-app-dotnet-sign-in-sign-in-out/display-aspnet-welcome.png" alt-text="Screenshot of sign in into a ASP.NET Core web app.":::
-
To sign out from the application, select the Sign out button.