我試圖在MVC 5網絡應用程序中實現Google身份驗證。身份驗證工作正常,但我會檢索個人資料和圖片信息。使用GoogleOAuth2AuthenticationOptions得到了redirect_uri_mismatch錯誤
要做到這一點,我添加了一個GoogleOAuth2AuthenticationOptions對象以指定其他聲明:
var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "xxxxxxxxxxxxxxxx",
ClientSecret = "xxxxxxxxxxxxxxxxx",
CallbackPath = new PathString("/Account/LoginCallback"),
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async context =>
{
context.Identity.AddClaim(new Claim("picture", context.User.GetValue("picture").ToString()));
context.Identity.AddClaim(new Claim("profile", context.User.GetValue("profile").ToString()));
}
}
};
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
但它會導致一個錯誤的URL生成: '?'
沒有在參數之前,這會導致redirect_uri_mismatch。
然而,當我使用簡單:
app.UseGoogleAuthentication(
clientId : "xxxxxxxxxxxxxxxxxxx",
clientSecret : "xxxxxxxxxxxxxxxxx");
它的工作。
有什麼想法?
非常感謝,我得到了我想要感謝您的回調URL,併爲資料圖片,我只是用這裏的解決方案mentionned:http://stackoverflow.com/questions/22820349/how-to-get-google-plus-profile-picture-in-c-sharp-mvc-authentication – feuille94 2014-09-23 23:11:06
在MVC5中不需要這條路由,只需要在@Saines中添加條目就可以了... – 2017-05-27 07:23:19