![](/img/trans.png)
[英]OAuth token endpoint failure on AspNet.Security.OAuth.Discord login: BadRequest
[英]ASP.Net Core - OAuth token endpoint failure: Status: BadRequest
对Google使用ASP.Net Core的身份验证时,我正在执行以下方案:
如果我等待了一段时间(可能是30分钟),如果我再次从步骤1开始,直到再次到达步骤4,我才遇到问题。如果为我的Core项目重新启动IIS ApplicationPool,则可以按照上面的步骤进行操作第1步起作用,但随后第4步显示此问题的场景。
我搜索了无休止的在线感觉,无济于事。 有谁能提供建议吗? 为什么这会第一次工作,然后在第二次,第三次尝试中失败?
在Google Pixel 3 XL手机上按照上述方案进行操作时,我收到以下错误消息:
System.Exception:SocialLoginController |错误| OAuth令牌端点失败:状态:BadRequest;标头:Vary:X-Origin,referer,Origin,Accept-Encoding日期:Sun,03 Mar 2019 09:35:45 GMT服务器:ESF Cache-控制:私有X-XSS-Protection:1; mode = block X-Frame-Options:SAMEORIGIN X-Content-Type-Options:nosniff Alt-Svc:quic =“:443”; ma = 2592000; v =“ 44,43,39”接受范围:无传输编码:分块;正文:{“ error”:“ invalid_grant”,
“ error_description”:“错误请求”};
我的Startup.cs类中用于Google身份验证的代码如下:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/login";
options.LogoutPath = "/signout";
});
services.AddAuthentication().AddGoogle(socialProvider.ProviderName, o =>
{
o.ClientId = [REMOVED]
o.ClientSecret = [REMOVED]
o.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
o.ClaimActions.Clear();
o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
o.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
o.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
o.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
o.ClaimActions.MapJsonKey("urn:google:profile", "link");
o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
o.CallbackPath = string.Format("/signin-{0}", socialProvider.ProviderName.ToLower());
o.SaveTokens = true;
o.Events.OnRemoteFailure = ctx =>
{
string message = UrlEncoder.Default.Encode(ctx.Failure.Message);
if (!string.IsNullOrEmpty(message) && message.Length > 1500)
{
message = message.Substring(0, 1499);
}
ctx.Response.Redirect(errorRedirectUrl + message);
ctx.HandleResponse();
return Task.FromResult(0);
};
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
当我启用“ UseDeveloperExceptionPage”时,还请参见下面显示错误的图像。
仅供参考,我完全无法在iPhone和台式机上复制该问题-我从未收到该问题,并且我可以尝试进行多次登录尝试,这些设备上似乎从未出现过该问题。
我迷路了!
我在这里能够识别出我的问题,而这个问题对于我发现的任何其他答案都是唯一的,但与我遇到的上述错误相同。
问题:在我的Pixel设备上,我有一个应用程序(My-App)可以在我在Chrome浏览器中访问的同一域上运行。 单击以通过Google登录时,我记得它曾经问过我要“在Chrome中打开”还是“在我的应用程序中打开”,并且我始终选择“在Chrome中打开”。
我卸载了My-App,现在无法复制该问题。 问题不见了。 每当它工作时,我多次尝试该方案都无济于事! 当我重新安装My-App时,问题又回来了。
修复:我需要解决的问题是我的Core项目正在运行My-App的域之外的其他域上运行,因此设备上不会出现关于应该打开Chrome还是应该打开My-App的困惑。 希望这将是我的解决办法!
谢谢阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.