【发布时间】:2014-11-16 21:24:52
【问题描述】:
我正在尝试在 MVC 5 网络应用程序中实现 Google 身份验证。身份验证工作正常,但我会检索个人资料和图片信息。
为此,我添加了一个 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");
它正在工作。
有什么想法吗?
【问题讨论】:
标签: asp.net-mvc google-authentication