我正在尝试在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);
Run Code Online (Sandbox Code Playgroud)
但它会导致生成错误的URL:
没有'?' 在参数之前,这会导致redirect_uri_mismatch.
但是,当我简单地使用时:
app.UseGoogleAuthentication(
clientId : "xxxxxxxxxxxxxxxxxxx",
clientSecret : "xxxxxxxxxxxxxxxxx");
Run Code Online (Sandbox Code Playgroud)
它正在发挥作用.
任何的想法 ?