Sam
Sam

Reputation: 30334

Additional permissions to Facebook authentication

I'm adding Facebook authentication to my new ASP.NET 5 MVC 6 application. I'm following this article: https://docs.asp.net/en/latest/security/authentication/sociallogins.html

I added the following code snippet to my Startup Configure method that gets me the basic information about the user.

app.UseFacebookAuthentication(options =>
{
   options.AppId = "myFacebookAppId";
   options.AppSecret = "myFacebookSecret";
});

I would like to request just one more things from Facebook which is the user's date of birth.

Where do I add this in my code?

Upvotes: 0

Views: 505

Answers (2)

Kévin Chalet
Kévin Chalet

Reputation: 42100

To request the user's date of birth, you need to:

  • Update the Scope property to make sure the user_birthday scope is included by the Facebook middleware when creating the authorization request. If you don't add the user_birthday scope, Graph API will never return the user's date of birth: options.Scope.Add("user_birthday");

  • Update the Fields property to include the birthday field, as suggested by @blowdart: options.Fields.Add("birthday");.

But note that the Fields property doesn't exist in ASP.NET 5 RC1 (the latest release ATM). Alternatively, you can also replace the UserInformationEndpoint property to include the fields you need:

options.UserInformationEndpoint = "https://graph.facebook.com/me?fields=birthday,email,name";

Upvotes: 1

blowdart
blowdart

Reputation: 56550

The options class has a Fields property;

/// <summary>
/// The list of fields to retrieve from the UserInformationEndpoint.
/// https://developers.facebook.com/docs/graph-api/reference/user
/// </summary>
public IList<string> Fields { get; }

Add birthday to the Fields property.

Upvotes: 0

Related Questions