相关疑难解决方法(0)

如何在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 Core 2 API调用被重定向(302)

我正在尝试将此项目https://github.com/asadsahi/AspNetCoreSpa从.net core 1.1 迁移 到2.0,但在成功登录后出现问题.登录后我的GET api调用例如https:// localhost:44331/api/profile/test结束重定向(302),我不知道为什么.我收到了持票人令牌,看起来不错.

请求标头格式:授权:承载[令牌]

[Route("api/[controller]")]
public class ProfileController : BaseController
{
    private readonly UserManager<ApplicationUser> _userManager;
    private readonly ILogger _logger;

    public ProfileController(ILoggerFactory loggerFactory, UserManager<ApplicationUser> userManager)
    {
        _logger = loggerFactory.CreateLogger<ProfileController>();
        _userManager = userManager;
    }

    [HttpGet("test")]
    public async Task<IActionResult> Test()
    {
        return  Json(ModelState.GetModelErrors());
    }
}

[Authorize]
[ServiceFilter(typeof(ApiExceptionFilter))]
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true)]
public class BaseController : Controller
{
    public BaseController()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    if (_hostingEnv.IsDevelopment())
    {
        services.AddSslCertificate(_hostingEnv);
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-identity asp.net-core-2.0

9
推荐指数
2
解决办法
5246
查看次数