我正在尝试使用OWIN进行外部登录Google / Facebook。
面临的问题是owin挑战不断将响应类型从令牌更改为代码。
这会从Google返回错误。如果我将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,
};
Google中间件设置:
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项目的基本设置。
答案 0 :(得分:0)
将response_type重写为令牌的解决方案如下:
GoogleOAuth2AuthenticationOptions googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "clientid",
ClientSecret = "secret",
Provider = new GoogleOAuth2AuthenticationProvider
{
OnApplyRedirect = context =>
{
string redirect = context.RedirectUri.Replace("response_type=code", "response_type=token");
context.Response.Redirect(redirect);
},
},
};
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
如果Google OAuth 2.0需要response_type = token,为什么Owin.google提供程序会使用response_type = code。
仍然存在问题。