Skip to content

thomas-bingel/AspNetCore5FromClaimsDataBinding

Repository files navigation

Asp Net Core 5 FromClaims DataBinding like [FromPath]

ASP.NET Core example on how to implement FromClaims attribute to easily access claims in a controller.

As an example I used the WeatherForecast template and added all necessary classes to the project.

[HttpGet]
public IEnumerable<WeatherForecast> Get([FromClaims] string zip)
{
    return _wartherForecastService.GetWeatherForecastForZip(zip);
}

You need 4 classes to get this working:

  • FromClaimsAttribute.cs
  • FromClaimsBindingSource.cs
  • FromClaimsDataBinderProvider.cs
  • FromClaimsModelBinder.cs

The last thing is to add the ModelBinderProvider:

services.AddControllers(config => {
    config.ModelBinderProviders.Insert(0, new FromClaimsDataBinderProvider());
});

All other classes / services are for testing purposes only.

Have Fun ;-)

About

ASP.NET Core example on how to implement FromClaims attribute to easily access claims in a controller

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages