How to retrieve facebook user profile picture within asp.net core MVC RC2

how to get profile picture from facebook in android
facebook oauth photo
facebook graph api : get profile picture full size
facebook profile pic api
instagram graph api get profile picture
picture facebook graph
facebook graph api get photo by id
facebook profile pic url

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" },
        });

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.

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).

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).

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).

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.

Retrieve User Details From Facebook In ASP.NET Core Applications, 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  Asp.NET MVC 5: How to retrieve user information on login with Facebook How to secure your HTTP API endpoints using Facebook as OAuth provider How we do the hiring process in my team

For anyone using Microsoft' OWIN Facebook Authentication extensions. You can extend the default FacebookAuthenticationProvider to obtain any requested (and granted) claims to the current identity. Then register that customer provider in the middleware. A simple custom provider would look like this...

public class CustomFacebookOAuthProvider: FacebookAuthenticationProvider
    {
        public override Task Authenticated(FacebookAuthenticatedContext context)
        {
            if (context.User.IsNotNull() && context.Id.IsNotNullOrEmpty())
            {
                //ADD THE CLAIMS YOU WANT YOUR APP TO CONSUME
                context.Identity.AddClaim(new Claim(Constants.ClaimsTypes.PhotoUrl
                    , "https://graph.facebook.com/{0}/picture?height={1}&width={1}".With(context.Id, Constants.UI.DEFAUL_PROFILE_PICTURE_DIMENS)));
            }

            return base.Authenticated(context);
        }
    }

The implementation is simple, we only need to override the Authenticated method, which will be called once the OAuth provider (Facebook in this example) has authenticated the user and returned the user details (translate this to a call to the UserInfo endpoint).

The context.User is a NewtonSoft.Json.JObject which can be desrialized into your own class...

var user = context.User.ToObject<FacebookOAuthUser>();

Just make sure you create the FacebookOAuthUser class with the required properties.

Once you have that provider in place, all you need to do register it...

app.UseFacebookAuthentication(new FacebookAuthenticationOptions
{
    AuthenticationType = "Facebook",
    Caption = "Sign-in with Facebook",
    SignInAsAuthenticationType = signInAsType,
    AppId = ApplicationSettings.FacebookAppID,
    AppSecret = ApplicationSettings.FacebookAppSecret,
    Provider = new CustomFacebookOAuthProvider()
});

Authenticating a user with LinkedIn in ASP.NET Core, In this article, we will learn how to retrieve user Details like Name, Profile Picture, Email, DOB and Gender after a successful Login with  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.

To get profile picture from Facebook, you need to configure Facebook options and subscribe at OnCreatingTicket event from OAuth.

services.AddAuthentication().AddFacebook("Facebook", options =>
                {

                    options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                    options.ClientId = "ClientId";
                    options.ClientSecret = "ClientSecret";
                    options.Fields.Add("picture"); // <- Add field picture
                    options.Events = new OAuthEvents
                    {
                        OnCreatingTicket = context =>
                        {
                            var identity = (ClaimsIdentity)context.Principal.Identity;
                            var profileImg = context.User["picture"]["data"].Value<string>("url");
                            identity.AddClaim(new Claim(JwtClaimTypes.Picture, profileImg));
                            return Task.CompletedTask;
                        }
                    };
                });

An introduction to OAuth 2.0 using Facebook in ASP.NET Core, ClaimsIssuer)); } // Add the Profile Picture claim var pictureUrl = user.Value<string​>("pictureUrl"); if (!string.IsNullOrEmpty(email)) { context.Identity. In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view. In Razor Pages, a PageModel can return a partial view represented as a PartialViewResult object. Referencing and rendering partial views is described in the Reference a partial view section.

ASP.NET Core Social Login, As we go through the flow, we'll illustrate it from a user's point of view, using the default MVC template with ASP.NET Core Identity, configured to  Hi, I have asp.net mvc 5 applicaton. I want to add "profile photo" for my users. This photo may be uploaded in profile setting and displayed on the site. I want to store the photo in data

Get Facebook Profile Picture for a logged in user, NET Core MVC EFCore project; Create an Identity based local login system Get profile picture from social login providers - enhance the experience. having your website asking Facebook for whom the user is - the social login eg. in this tutorial we will automatically fetch the users profile picture from  Retrieve User Details From Facebook In ASP.NET Core Applications Jun 30, 2017. In this article, we will learn how to retrieve user Details like Name, Profile Picture, Email, DOB and Gender after a successful Login with Facebook in ASP.NET Core Applications.

Authentication Using LinkedIn In ASP.NET Core 2.0, Hi All, I am using Visual Studio 2013 Web Forms and I have activated the external login via Facebook. While the registration looks fine and  In our previous article wehave explained about how to customizing ASP.NET MVC 5 Security and Creating User Role and User Role base Menu Management (Dynamic menu using MVC and AngularJS) In this article we will see in detail about using ASP.NET Identity in MVC Application. To upload and store User Profile Image to AspNetUsers table in SQL Server.

Comments
  • Thanks Set for clarifying that the claims principal collection only contains data from the UserInformationEndpoint.
  • Can you point me to an example that shows how to call the facebook api methods
  • check this stackoverflow.com/questions/11442442/…
  • very unhelpful answer... doesn't explain anything about the Facebook auth middleware...