Ahm*_*mad 5 authentication facebook claims asp.net-core
我正在尝试使用 ASP.NET Core 1.0 中的 Facebook 身份验证中间件检索用户个人资料图片。我设法添加了这些配置以使用户图片可用
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["Authentication:Facebook:AppId"],
AppSecret = Configuration["Authentication:Facebook:AppSecret"],
Scope = { "public_profile" },
Fields = { "picture" }
});
Run Code Online (Sandbox Code Playgroud)
并检索数据
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
Run Code Online (Sandbox Code Playgroud)
和
var userName = info.Principal.FindFirstValue(ClaimTypes.GivenName);
Run Code Online (Sandbox Code Playgroud)
但是我现在如何检索用户图片,因为它没有声明类型?
正如 Set 在他的回答中所说,您可以 像这样使用 Facebook Graph API获取图片https://graph.facebook.com/{user-id}/picture。
示例代码:
var info = await _signInManager.GetExternalLoginInfoAsync();
var identifier = info.Principal.FindFirstValue(ClaimTypes.NameIdentifier);
var picture = $"https://graph.facebook.com/{identifier}/picture";
Run Code Online (Sandbox Code Playgroud)
您可能想检查是否info为空,是否info.LoginProvider为 facebook。
| 归档时间: |
|
| 查看次数: |
1377 次 |
| 最近记录: |