【发布时间】:2016-12-27 14:50:10
【问题描述】:
我正在尝试使用 OWIN 外部登录到 Google/Facebook。
面临的问题是 owin 挑战不断将响应类型从令牌更改为代码。
这会从谷歌返回一个错误。如果我将 response_type 更改为 token (response_type=token) 就可以了。
这是 OAuth 选项
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true,
};
谷歌中间件设置:
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "clientid",
ClientSecret = "client secret",
});
这是挑战:
var properties = new AuthenticationProperties() { AllowRefresh = true, RedirectUri="mywebsite.co.za" };
Request.GetOwinContext().Authentication.Challenge(properties,LoginProvider);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
response.RequestMessage = Request;
return Task.FromResult(response);
OWIN 是通用 MVC API 项目的基本设置。
【问题讨论】:
标签: c# oauth-2.0 owin google-oauth