如何在asp.net核心MVC RC2中检索Facebook用户个人资料图片

问题描述:

使用ASP.NET Core MVC RC2我正在尝试检索Facebook用户个人资料图片.为此,我在启动类的Configure方法中添加了以下几行

Using ASP.NET Core MVC RC2 I am trying to retrieve the Facebook user profile picture. To do this I have the following lines in the Configure method of the Startup class

            app.UseFacebookAuthentication(new FacebookOptions()
        {
            AppId = Configuration["Authentication:Facebook:AppId"],
            AppSecret = Configuration["Authentication:Facebook:AppSecret"],
            Scope = { "user_birthday" },
            Fields = { "birthday", "picture" },
        });

在AccountControllers ExternalLoginCallback方法中,我期望在ClaimsPrincipal集合中看到该图片的数据,可以通过info.Principal进行访问,但是我看不到与该图片相关的任何索赔.

In the AccountControllers ExternalLoginCallback method I was expecting to see the data for the picture in the ClaimsPrincipal collection which can be accessed via info.Principal but I cannot see any claim associated with picture.

这是检索Facebook用户个人资料图片的正确方法还是我遗漏了某些东西?

Is this the right way to retrieve the Facebook user profile picture or am I missing something?

使用第三方身份验证,您仅会获得有关用户身份的信息(用户身份验证).

Using 3rd Party Authentication, you are only get information about who user is (user authentication).

使用Facebook身份验证,成功登录后,您会收到对Facebook API的访问令牌和用户数据(声明)的集合,仅来自 https://graph.facebook.com/v2.6/me ).

Using Facebook Authentication, after successful login you receive an access token to Facebook API and a collection of user data (claims) only from UserInformationEndpoint (https://graph.facebook.com/v2.6/me).

此后,如果要获取其他任何特定于用户的信息(例如您的情况下的用户图片),应调用Facebook API方法-

After that, you should call Facebook API methods if you want to get any other user specific information (like user picture in your case - Facebook Graph API. User Picture).

如果您对声称已完成Facebook登录的ASP.Core实现充满兴趣的内容,请查看

If you are interesting about claims that ASP.Core implementation of Facebook login is filled, looks into CreateTicketAsync method in FacebookHandler class - here the collection of claims is created.