好的,我目前正在使用ASP.Net Core 1.1.2和ASP.NET Core Identity 1.1.2。
Startup.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);
//
}
到目前为止,一切都很顺利。但是我卡在这里了。我阅读了许多关于访问令牌和称为pictureUrl等的声明的文章。但是Principal不包含其中任何一个。
所以问题是:如何在ExternalLoginCallback函数中检索配置文件图像?