如何将完整的身份用户对象从CustomOAuthBearerAuthenticationProvider传递给AuthorizationFilterAttribute。
public class CustomOAuthBearerAuthenticationProvider : OAuthBearerAuthenticationProvider
{
public override Task ValidateIdentity(OAuthValidateIdentityContext context)
{
var appUserManager =
context.OwinContext.GetUserManager<ApplicationUserManager>();
var identity = context.Ticket.Identity;
var user = appUserManager.FindByIdAsync(identity.GetUserId()).Result;
context.Ticket.Identity.AddClaim(new Claim("PSK", user.PSK));
return base.ValidateIdentity(context);
}
}
public class TwoFactorAuthorizeAttribute : AuthorizationFilterAttribute
{
public override Task OnAuthorizationAsync(HttpActionContext
actionContext, System.Threading.CancellationToken cancellationToken)
{
var principal = actionContext.RequestContext.Principal as
ClaimsPrincipal;
var psk= principal?.FindFirst("psk").Value; //I want to read full object rather than individual property
}
}