Search code examples
facebookoauthauthorizationfacebook-access-tokenimplicit

How does one get the app access token for debug_token inspection on Facebook?


It is suggested that whether your app uses code or token as your response_type you should perform an automated check on the access_token to confirm that the token belongs to the person the app expects it to belong to and that it was your app that generated the token.

You are supposed to do this on

GET graph.facebook.com/debug_token?
 input_token={token-to-inspect}
 &access_token={app-token-or-admin-token}

where app-token is app_id|app_secret and token-to-inspect is the user's access_token. Also, I think from reading the documentation you can retrieve an app-token by doing a client-credentials call with the app_id and app_secret.

This is fine with an authorization flow implemented server-side, but what if you're using the implicit method and chose response_type as token (and for whatever reason aren't using FB's javascript SDK)? How do you safely get that app-token without leaking your app_secret? How does FB's SDK do it?


Solution

  • You can generate an app_token in your Facebook developer panel here and then simply save it into a config file server side. From the developer's page:

    App tokens do not expire and should be kept secret as they are related to your app secret.

    On my page, I use the following flow:

    1. The user authenticates with the Facebook JS SDK, and then sends his token + uid to the server.
    2. The server validates that the given token is related to the given person via a call to the "debug_token" method, that you spoke of.
    3. If the token + uid combination is valid, it authenticates the user server side.

    I hope this helps.