facebookstormpath

Facebook Attribute Mapping with StormPath to retrieve the Facebook ID


This is driving me cray. I am trying to retrieve the Facebook id after logging in. I am assuming I have to use the attribute mapping in order to achieve this? Any thoughts?

enter image description here

enter image description here


Solution

  • Heyo, Just thought I'd reply here too in case anyone else has questions about this.

    I looked at the Facebook scopes reference page, and it says that public_profile is the scope that contains the user ID. So, I went to my Facebook Directory, and under 'Provider Configuration' on the 'Scopes' tab, I added public_profile. Under the 'Attribute Mappings' tab, I added id as the Attribute Name and set customData.id as the 'Stormpath Field Name'.

    When users log in to my web app using their Facebook credentials, their ID is saved directly to their account's customData:

    {
      "id": "1260737122323"
    }
    

    To grab this data from the Account's customData and display it on the profile page of the React-Express sample project, you need to do two things:

    1. Ensure that the web.me.expand.customData config is set to true in order to have the custom data fields populated,
    2. Add a new field on the profile page with name="customData.id", like this:

    enter image description here

    This is covered in the docs under the Access custom data fields by prefixing field names with customData section.