小编Ytr*_*amX的帖子

OWIN身份验证,使当前令牌失效并删除co​​okie

我有一个OWIN中间件用于身份验证.我们有两种类型的身份验证.第一种类型是使用以下配置的承载令牌

var OAuthOptions =  new OAuthAuthorizationServerOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
        TokenEndpointPath = new PathString("/Token"),
        Provider = new ApplicationOAuthProvider(PublicClientId),
        AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
        AllowInsecureHttp = true,
        AccessTokenFormat = new SecureTokenFormatter(GetMachineKey())
    };
Run Code Online (Sandbox Code Playgroud)

第二种类型使用身份验证cookie进行外部登录

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive,
    CookieHttpOnly = true,
    CookieSecure = CookieSecureOption.SameAsRequest,
    CookieName = ".AspNet." + DefaultAuthenticationTypes.ExternalCookie,
    ExpireTimeSpan = TimeSpan.FromMinutes(5),
    TicketDataFormat = new SecureTokenFormatter(GetMachineKey())
});
Run Code Online (Sandbox Code Playgroud)

当用户注销时,我们实际发出了两个Logout

Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie);
Run Code Online (Sandbox Code Playgroud)

和

Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ExternalBearer);
Run Code Online (Sandbox Code Playgroud)

对于第一个,我希望看到从浏览器中删除.AspNet.ExternalCookie Cookie,但事实并非如此.对于第二个,我希望我的令牌失效,而User.Current.Identity = null,这不是.

那么我怎么能1)以物理方式注销当前会话的当前身份?2)从浏览器中删除外部Cookie?

c# authentication owin

5
推荐指数
1
解决办法
9068
查看次数

标签 统计

authentication ×1

c# ×1

owin ×1