Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.25 KB

README.md

File metadata and controls

51 lines (39 loc) · 1.25 KB

AspNetCore.ClaimsValueProvider

The claims value provider allows binding a controller parameter to a claim that is associated with the current user, such a user ID, name, or email

Build status NuGet

Usage

Installation

.NET CLI
> dotnet add package AspNetCore.ClaimsValueProvider
Package Manager
PM> Install-Package AspNetCore.ClaimsValueProvider

Startup.cs

Configure the application to use the value provider.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc(options =>
    {
        options.AddClaimsValueProvider();
    });
}

Controller

In a controller action, use the FromClaim attribute, along with a claim type, to bind the parameter

public class MyController : Controller
{
    [HttpGet("")]
    public IActionResult Get(
        [FromClaim(ClaimTypes.NameIdentifier)]Guid userId,
        [FromClaim(ClaimTypes.Email)]string email)
    {
        ...
    }
}