将C#Owin响应类型从代码更改为令牌
我正在尝试使用OWIN外部登录到Google/Facebook 面临的问题是owin挑战不断将响应类型从令牌更改为代码 质询生成以下URL: 这将从google返回一个错误。如果我将response\u type更改为token(response\u type=token),它会工作 下面是OAuth选项将C#Owin响应类型从代码更改为令牌,c#,oauth-2.0,owin,google-oauth,C#,Oauth 2.0,Owin,Google Oauth,我正在尝试使用OWIN外部登录到Google/Facebook 面临的问题是owin挑战不断将响应类型从令牌更改为代码 质询生成以下URL: 这将从google返回一个错误。如果我将response\u type更改为token(response\u type=token),它会工作 下面是OAuth选项 OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath =
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项目的基本设置。将响应类型重写为令牌的解决方案如下:
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);
它仍然回避了一个问题,如果googleoauth2.0需要response_type=token,那么Owin.google提供者为什么要使用response_type=code呢