小编kin*_*kin的帖子

无法使用Owin注销Web Api

我已经使用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());
        }

在AuthorizationServerProvider中:

 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;
                } …

asp.net-web-api owin

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

标签 统计

asp.net-web-api ×1

owin ×1