Skip to content

Latest commit

 

History

History
 
 

web-app-aspnet

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages page_type name description products urlFragment
csharp
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.
azure
azure-active-directory
ms-graph
ms-identity-docs-code-csharp-sign-in

ASP.NET Core 6.0 Web App - Sign-in user | Microsoft identity platform

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.

Quickstart and tutorial guides for this sample

Prerequisites

Setup

1. Register the web API application in your Azure Active Directory

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.

2. Configure the web app

  1. Open the ~/sign-in-webapp/WebApp.csrpoj in your code editor.

  2. 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"
        }   
      ],

Run the application

1. Run the webapp

  1. Execute the following command to get the app up and running:

    dotnet run

2. Sign in to the web app

  1. Once the web app is listening, navigate to https://localhost:5001
  2. Sign-in with your user credentials.

A screenshot of an ASP.NET Core 6.0 Web App displaying a response from Microsoft Graph.

3. Sign out

  1. Select Sign out

A screenshot of an ASP.NET Core 6.0 Web App indicating the user signed-out and allowing click "Sign in" to signin again.

About the code

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

Reporting problems

Sample app not working?

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.

  1. Search the GitHub issues in the repository - your problem might already have been reported or have an answer.
  2. Nothing similar? Open an issue that clearly explains the problem you're having running the sample app.

All other issues

⚠️ 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.

Contributing

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.