我懶得寫一個格式正確的答案,我把這些評論放在代碼中讓自己記住如何解決這個問題。這不是一個真正的問題,只是我從來沒有想過要正確閱讀的東西:)但是這是你可以做的,以使其工作。有2個選項可以做到這一點。我已經嘗試過,兩個選項都很好。我現在第一個去了,這真的沒關係。這裏是我在Startup.Auth.cs文件中的評論。
// My notes to resolve Google Error: redirect_uri_mismatch error
// By default GoogleOAuth2AuthenticationOptions has CallbackPath defined as "/signin-google"
// https://msdn.microsoft.com/en-us/library/microsoft.owin.security.google.googleoauth2authenticationoptions(v=vs.113).aspx
// But the real path should be Controller/Action: for this application it is "/Account/ExternalLoginCallback"
// There are 2 ways to define it properly:
// 1) Add a new route in RouteConfig.cs that will map "/signin-google" into "/Account/ExternalLoginCallback":
// routes.MapRoute(name: "signin-google", url: "signin-google", defaults: new { controller = "Account", action = "ExternalLoginCallback" });
// Remember, in Google Developers Console you must have your "/signin-google" redirect URI, since that is what your app sends to Google
// 2) Completely overwrite built-in "/signin-google" path.
// Owerwrite CallbackPath right here by adding this line after ClientSecret:
// CallbackPath = new PathString("/Account/ExternalLoginCallback")
// Remember, in Google Developers Console you must have "/Account/ExternalLoginCallback" redirect URI, since now that is what your app sends to Google
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "xxxxxxxxxxxxxxxxxxxx",
ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxx"
});
如果你把谷歌控制檯那個url你想如何出現在你的MVC項目?你的意思是「它的工作原理」,谷歌控制檯讓你保存的網址,或者你可以登錄您的網站與谷歌帳戶?女巫我懷疑會工作。 – SilentTremor
@SilentTremor感謝您的評論。我不得不在Google開發者控制檯中輸入signin-google,而不是使用MVC默認帳戶控制器的ExternalLoginCallback。它的工作意味着我可以登錄。讓我驚訝的是,我也瞭解你的意見。我希望有人向我解釋這個問題,因爲我打算在我的網站上添加更多的OAuth提供商,我希望完全瞭解這個問題。 – dsb