小编Leo*_*sus的帖子

如何在c#MVC身份验证中获取google plus个人资料图片

我正在开发一个使用Google登录作为默认提供程序的C#ASP.NET MVC 5应用程序.登录功能正常,我可以获得用户的电子邮件和名称.我需要的一件事是获取用户的个人资料图片.

我怎样才能做到这一点?

到目前为止,我使用默认的MVC auth"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);
Run Code Online (Sandbox Code Playgroud)

这就是我如何获得电子邮件地址.但是个人资料图片怎么样?

我是否需要使用其他形式的身份验证?

c# asp.net-mvc gmail google-plus

13
推荐指数
2
解决办法
9878
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

gmail ×1

google-plus ×1