我从来没有理解过为什么,但在我的情况下,我需要在签到后使机票有效:
var userIdentity = await user.CreateIdentityAsync(DefaultAuthenticationTypes.ExternalBearer);
ctx.Authentication.SignIn(userIdentity);
AuthenticationTicket ticket = new AuthenticationTicket(userIdentity, null);
ctx.Validated(ticket);
我不是真的在同一个背景下。在我的例子中,有一个自定义的身份验证提供程序继承了
Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationProvider
:
public class CustomBearerAuthenticationProvider:OAuthBearerAuthenticationProvider
{
public CustomBearerAuthenticationProvider() : base()
{
this.OnValidateIdentity = (context) => Task.Run(() =>
{
var identity = this.CreateApplicationIdentity(user);
context.OwinContext.Authentication.SignIn(identity);
AuthenticationTicket ticket = new AuthenticationTicket(identity, null);
context.Validated(ticket);
});
}
}
context
Microsoft.Owin.Security.OAuth.OAuthValidateIdentityContext