How to verify Facebook access token?

后端 未结 6 1873
囚心锁ツ
囚心锁ツ 2020-11-28 03:26

There\'s only thing that server has to do; just check any access token\'s validity.

Clients send to the server user id and access token obtained by FB.getLogin

6条回答
  •  孤城傲影
    2020-11-28 03:55

    Exchange Access Token for Mobile Number and Country Code (Server Side OR Client Side)

    You can get the mobile number with your access_token with this API https://graph.accountkit.com/v1.1/me/?access_token=xxxxxxxxxxxx. Maybe, once you have the mobile number and the id, you can work with it to verify the user with your server & database.

    xxxxxxxxxx above is the Access Token

    Example Response :

    {
       "id": "61940819992708",
       "phone": {
          "number": "+91XX82923912",
          "country_prefix": "91",
          "national_number": "XX82923912"
       }
    }
    


    Exchange Auth Code for Access Token (Server Side)

    If you have an Auth Code instead, you can first get the Access Token with this API - https://graph.accountkit.com/v1.1/access_token?grant_type=authorization_code&code=xxxxxxxxxx&access_token=AA|yyyyyyyyyy|zzzzzzzzzz

    xxxxxxxxxx, yyyyyyyyyy and zzzzzzzzzz above are the Auth Code, App ID and App Secret respectively.

    Example Response

    {
       "id": "619XX819992708",
       "access_token": "EMAWdcsi711meGS2qQpNk4XBTwUBIDtqYAKoZBbBZAEZCZAXyWVbqvKUyKgDZBniZBFwKVyoVGHXnquCcikBqc9ROF2qAxLRrqBYAvXknwND3dhHU0iLZCRwBNHNlyQZD",
       "token_refresh_interval_sec": XX92000
    }
    

    Note - This is preferred on the server-side since the API requires the APP Secret which is not meant to be shared for security reasons.

    Good Luck.

提交回复
热议问题