![](/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.