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