ASP.NET Core v2.1: User Profile
This tutorial will show you how to get the user's profile and display it. We recommend you to Log in to follow this quickstart with examples configured for your account.
I want to integrate with my app15 minutes
I want to explore a sample app2 minutes
Get a sample configured with your account settings or check it out on Github.
Get the Profile
The OIDC middleware extracts the user's information from the ID Token and adds it as claims to the
The seed project contains a controller action and view which display the claims associated with a user. Once a user has logged in, you can go to
/Account/Claims to see these claims.
You can create a custom user profile page for displaying a user's name, email address and profile image.
Create a view model containing the basic user profile information:
Add a new
Profile action to the
AccountController and extract the relevant claims. Add the claims to a new instance of
UserProfileViewModel passed to the view. Add the
[Authorize] attribute to the action so only authenticated users can access the action:
User.Identity.Name property looks for a claim of a type
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name on the user object. Auth0 passes the name of the user in the
name claim of the ID Token, but this does not get automatically matched to the
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name type. This means that
User.Identity.Name will return null.
You can control the claim type that ASP.NET Core retrieves when accessing the name through
User.Identity.Name. To achieve this, update the OIDC authentication handler registration in the
Startup class. Set the
NameClaimType of the
TokenValidationParameters property to
name. ASP.NET Core will retrieve the value of the
name claim passed in the ID Token when you access the name of the user with the
You must update the list of scopes to request the
profile scope. The user's profile information is returned as claims in the ID Token.
Next create a view. For the view, display user's profile card at the top with the user's name, email address and profile image.
Now when you log in and go to the URL
/Account/Profile, you will see the user's profile with the information.
You can put a link in the top navigation bar to display the user's name. When the user clicks on their name, you can navigate them to their profile page.
Go to the
Views/Shared/_Layout.cshtml file and update the
Navbar section to display the user's name and link to the
Profile action in the
Now, after the user has logged in, the user's name is displayed in the top-right corner of the navigation bar: