【发布时间】:2016-11-25 21:15:39
【问题描述】:
我已使用 owin 登录,但无法退出。
在开始:
在 AuthorizationServerProvider 中:
公共覆盖任务 ValidateClientAuthentication(OAuthValidateClientAuthenticationContext 上下文) { context.Validated(); 返回 Task.FromResult(null); } 公共覆盖异步任务 GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext 上下文) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*"}); 使用 (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(); 返回; } } //上下文.请求。 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); } 别的 { context.Request.Context.Authentication.SignOut(); } context.Validated(身份); }
在 ApiController 中:
[HttpGet]
[ActionName("logout")]
public IHttpActionResult logout()
{
Request.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
this.Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
return Ok();
}
我调用注销然后使用旧令牌但它仍然可以使用。所以注销不起作用? 感谢收看。
【问题讨论】:
标签: asp.net-web-api owin