Asp.net web api Can';t使用Owin注销Web Api

Asp.net web api Can';t使用Owin注销Web Api,asp.net-web-api,owin,Asp.net Web Api,Owin,我已使用owin登录,但无法注销。 首先: 我调用注销,然后使用旧令牌,但它仍然可以使用。那么注销不起作用了吗? 谢谢你的手表。Owin不是这样工作的。没有注销。您获得一个令牌,并且该令牌在设定的时间内有效。令牌将一直有效,直到过期 您可以自己添加一个额外的层,基本上是在生成令牌时,将其与到期数据和有效状态一起存储在某个位置。当您调用logout时,您将令牌更新为无效,然后当它;如果已使用,则在通过owin检查后,您可以运行自己的检查并使其无效 老实说,我不想为这个费心。如果您走这条路,这意

我已使用owin登录,但无法注销。
首先:

我调用注销,然后使用旧令牌,但它仍然可以使用。那么注销不起作用了吗?
谢谢你的手表。

Owin不是这样工作的。没有注销。您获得一个令牌,并且该令牌在设定的时间内有效。令牌将一直有效,直到过期

您可以自己添加一个额外的层,基本上是在生成令牌时,将其与到期数据和有效状态一起存储在某个位置。当您调用logout时,您将令牌更新为无效,然后当它;如果已使用,则在通过owin检查后,您可以运行自己的检查并使其无效

老实说,我不想为这个费心。如果您走这条路,这意味着您没有使用Owin来完成它的任务,即应用程序级身份验证,而不是用户身份验证。两者之间有着巨大的差异

因此,我的建议是使用会员制进行用户身份验证,并将owin内容分开。如果你这样做,那么你实际上可以注销某人


所以底线是:owin令牌在到期之前是有效的。

owin不是这样工作的。没有注销。您获得一个令牌,并且该令牌在设定的时间内有效。令牌将一直有效,直到过期

您可以自己添加一个额外的层,基本上是在生成令牌时,将其与到期数据和有效状态一起存储在某个位置。当您调用logout时,您将令牌更新为无效,然后当它;如果已使用,则在通过owin检查后,您可以运行自己的检查并使其无效

老实说,我不想为这个费心。如果您走这条路,这意味着您没有使用Owin来完成它的任务,即应用程序级身份验证,而不是用户身份验证。两者之间有着巨大的差异

因此,我的建议是使用会员制进行用户身份验证,并将owin内容分开。如果你这样做,那么你实际上可以注销某人


因此,底线是:owin代币在到期之前是有效的。

你能帮我回答这个问题吗:你能帮我回答这个问题吗: public void ConfigureOAuth(IAppBuilder app) { OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathString("/token"), AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(20), Provider = new AuthorizationServerProvider(), AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie }; app.UseOAuthBearerTokens(OAuthServerOptions); app.UseCookieAuthentication(new CookieAuthenticationOptions()); } public override Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context) { context.Validated(); return Task.FromResult(null); } public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*"}); using (demoEntities _repo = new demoEntities()) { if (!_repo.users.Where(x => x.username == context.UserName && x.pass == context.Password).Any()) { context.SetError("invalid_grant", "wrong."); //context.Rejected(); return; } } //context.Request. var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("sub", context.UserName)); identity.AddClaim(new Claim("role", "user")); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); if (context.Request.Path.Value != "/api/apidemo/logout") { context.Request.Context.Authentication.SignIn(identity); } else { context.Request.Context.Authentication.SignOut(); } context.Validated(identity); }
  [HttpGet]
    [ActionName("logout")]
    public IHttpActionResult logout()
    {
        Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
        this.Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
        return Ok();
    }