Skip to content

Conveniently provides claims from a ClaimsPrincipal in controller actions. (Forked to update for AspNet Core 2.0)

License

Notifications You must be signed in to change notification settings

mthamil/AspNetCore.ClaimsValueProvider

 
 

Repository files navigation

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

.csproj

<PackageReference Include="AspNetCore.ClaimsValueProvider.Fork" Version="2.0.0" />

Startup.cs

Configure the application to use the value provider.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc(options =>
    {
        options.ValueProviderFactories.Add(new ClaimsValueProviderFactory());
    });
}

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

Conveniently provides claims from a ClaimsPrincipal in controller actions. (Forked to update for AspNet Core 2.0)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%