1

I'm using this piece of code in my program.cs file to authenticate against Facebook and return the users Facebook profile image. It does work but the problem is the image is very small (50 x 50). Is there a way of getting back a larger image?

builder.Services.AddAuthentication(options =>
{
    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;

})
 .AddFacebook(options =>
  {
      options.AppId = "xxxx";
      options.AppSecret = "xxxx";

      options.Fields.Add("picture");
      options.Events = new OAuthEvents
      {
          OnCreatingTicket = (context) =>
          {
              ClaimsIdentity identity = (ClaimsIdentity)context.Principal.Identity;
              string profileImg = context.User.GetProperty("picture").GetProperty("data").GetProperty("url").ToString();
              identity.AddClaim(new Claim("image", profileImg));
              return Task.CompletedTask;
          }
      };

  });
1

1 Answer 1

1

If anyone else is stuck on this then the answer is pretty simple, for a 500 x 500 image just do this:-

Change this line:

options.Fields.Add("picture");

for this:

options.Fields.Add("picture.width(500).height(500)");

Not the answer you're looking for? Browse other questions tagged or ask your own question.