好的...我目前正在使用 ASP.NET Core 1.1.2 和 ASP.NET Core Identity 1.1.2。
其中重要的部分是启动.cs看起来像这样:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
SignInScheme = "Identity.External", // this is the name of the cookie middleware registered by UseIdentity()
ClientId = Configuration["ExternalLoginProviders:Google:ClientId"],
ClientSecret = Configuration["ExternalLoginProviders:Google:ClientSecret"]
});
}
GoogleOptions 附带 Microsoft.AspNetCore.Authentication.Google nuget 包。
回调函数在AccountController.cs看起来像这样:
[HttpGet]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
//... SignInManager<User> _signInManager; declared before
ExternalLoginInfo info = await _signInManager.GetExternalLoginInfoAsync();
SignInResult signInResult = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
string email = info.Principal.FindFirstValue(ClaimTypes.Email);
string firstName = info.Principal.FindFirstValue(ClaimTypes.GivenName);
string lastName = info.Principal.FindFirstValue(ClaimTypes.Surname);
//
}
所以,到目前为止一切都运行良好。我被困在这里了。我读了很多关于 accesstokens 和名为 pictureUrl 的声明等的文章。但校长不包含任何这些。
所以问题是:如何在ExternalLoginCallback函数中检索一次个人资料图像?