Equivalent to ClaimsAuthorizationAttribute in Microsoft.AspNet.Identity 3
Does anyone know the equivalent:
[ClaimsAuthorization(ClaimType="", ClaimValue="")]
at Microsoft.AspNet.Identity 3 (beta6)
Example with ID 2.1:
[HttpGet]
[ClaimsAuthorization(ClaimType="ManageStore", ClaimValue="Allowed")]
public IActionResult Register()
{
return View();
}
+3
source to share
1 answer
An approach
@tailmax works fine with ASP.NET 5 beta4, but will not work with beta, beta6 and later as it is AuthorizeAttribute
completely updated and doesn't reveal anymore OnAuthorization
(it's just a token now).
The recommended approach is to use the new authorization service to configure the new policy and just use AuthorizeAttribute
:
public void ConfigureServices([NotNull] IServiceCollection services) {
services.ConfigureAuthorization(options => {
options.AddPolicy("ManageStore", policy => {
policy.RequireAuthenticatedUser();
policy.RequireClaim("ManageStore", "Allowed");
});
});
}
public class StoreController : Controller {
[Authorize(Policy = "ManageStore"), HttpGet]
public async Task<IActionResult> Manage() { ... }
}
+3
source to share