Misiu / AspNetCore.ClaimsValueProvider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)
    {
        ...
    }
}

About

License:MIT License


Languages

Language:C# 100.0%