我有一个可行的解决方案,但我想知道这是否是正确的方法。这是我到目前为止得到的。
我使用的是ASP.Net Core1.1.2和ASP.NET核心标识1.1.2。
Startup.cs中的重要部分如下所示:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
app.UseFacebookAuthentication(new FacebookOptions
{
AuthenticationScheme = "Facebook",
AppId = Configuration["ExternalLoginProviders:Facebook:AppId"],
AppSecret = Configuration["ExternalLoginProviders:Facebook:AppSecret"]
});
}FacebookOptionscomes与Microsoft.AspNetCore.Authentication.Facebook 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);
byte[] thumbnailBytes = null;
if (info.LoginProvider == "Facebook")
{
string nameIdentifier = info.Principal.FindFirstValue(ClaimTypes.NameIdentifier);
string thumbnailUrl = $"https://graph.facebook.com/{nameIdentifier}/picture?type=large";
using (HttpClient httpClient = new HttpClient())
{
thumbnailBytes = await httpClient.GetByteArrayAsync(thumbnailUrl);
}
}
//...
}因此,这段代码运行得非常好,但是,正如前面提到的,这是正确的方法吗--(技术上,不是基于意见的)?
发布于 2019-10-30 02:45:34
我只使用标识符从图形api中获得图像。
$"https://graph.facebook.com/{identifier}/picture?type=large";https://stackoverflow.com/questions/45855660
复制相似问题