【发布时间】:2014-04-02 18:46:16
【问题描述】:
我正在开发一个使用 Google 登录作为默认提供程序的 C# ASP.NET MVC 5 应用程序。登录功能正常,我可以获取用户的电子邮件和姓名。 我需要做的一件事是获取用户的个人资料图片。
我怎样才能做到这一点?
到目前为止,我使用默认的 MVC 身份验证“UseGoogleAuthentication”。
Microsoft.Owin.Security.Google.GoogleAuthenticationOptions a = new Microsoft.Owin.Security.Google.GoogleAuthenticationOptions();
var googleOption = new GoogleAuthenticationOptions()
{
Provider = new GoogleAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
var rawUserObjectFromFacebookAsJson = context.Identity;
context.Identity.AddClaim(new Claim("urn:google:name", context.Identity.FindFirstValue(ClaimTypes.Name)));
context.Identity.AddClaim(new Claim("urn:google:email", context.Identity.FindFirstValue(ClaimTypes.Email)));
return Task.FromResult(0);
}
}
};
app.UseGoogleAuthentication(googleOption);
这就是我获取电子邮件地址的方式。但是头像呢?
我需要使用其他形式的身份验证吗?
【问题讨论】:
标签: c# asp.net-mvc gmail google-plus