This example shows how to extract user profile information from claims and display the user's profile in your application.
You can read a quickstart for this sample here.
-
Ensure that you have replaced the appsettings.json file with the values for your Auth0 account.
-
Run the application from the command line:
dotnet run
-
Go to
http://localhost:3000
in your web browser to view the website.
In order to run the example with docker you need to have Docker installed.
Execute in command line sh exec.sh
to run the Docker in Linux or macOS, or .\exec.ps1
to run the Docker in Windows.
// /ViewModels/UserProfileViewModel.cs
public class UserProfileViewModel
{
public string EmailAddress { get; set; }
public string Name { get; set; }
public string ProfileImage { get; set; }
}
// /Controllers/AccountController.cs
[Authorize]
public IActionResult Profile()
{
return View(new UserProfileViewModel()
{
Name = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value,
EmailAddress = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value,
ProfileImage = User.Claims.FirstOrDefault(c => c.Type == "picture")?.Value
});
}
<!-- /Views/Accounts/Profile.cshtml -->
@model SampleMvcApp.ViewModels.UserProfileViewModel
@{
ViewData["Title"] = "User Profile";
}
<div class="row">
<div class="col-md-12">
<div class="row">
<h2>@ViewData["Title"].</h2>
<div class="col-md-2">
<img src="@Model.ProfileImage"
alt="" class="img-rounded img-responsive" />
</div>
<div class="col-md-4">
<h3>@Model.Name</h3>
<p>
<i class="glyphicon glyphicon-envelope"></i> @Model.EmailAddress
</p>
</div>
</div>
</div>
</div>