[ACCEPTED]-Facebook OAuth: custom callback_uri parameters-facebook-oauth

Accepted answer
Score: 106

I figured out the answer; rather than adding 4 additional parameters to the redirect URL, you 3 can add a state parameter to the request to https://www.facebook.com/dialog/oauth:


That 2 state parameter is then passed to the callback 1 URL.

Score: 12

If, for any reason, you can't use the option 4 that Jacob suggested as it's my case, you 3 can urlencode your redirect_uri parameter before passing it and 2 it will work, even with a complete querystring 1 like foo=bar&morefoo=morebar in it.

Score: 4

I was trying to implement a Facebook login 16 workflow against API v2.9 following this tutorial. I 15 tried the solutions described above. Manuel's 14 answer is sort of correct, but what I observed 13 is url encoding is not needed. Plus, you 12 can only pass one parameter. Only the first 11 query parameter will be considered, the 10 rest will be ignored. Here is an example,

  1. Request 9 a code via https://www.facebook.com/v2.9/dialog/oauth?client_id={app-id}&redirect_uri=http://{url}/login-redirect?myExtraParameter={some-value}

  2. You'd get a callback for your 8 url. It will look like http://{url}/login-redirect?code={code-from-facebook}&myExtraParameter={value-passed-in-step-1}. Note that facebook 7 would make a callback with myExtraParameter. You can extract 6 the value for myExtraParameter from callback url.

  3. Then you 5 can request access token with https://graph.facebook.com/v2.9/oauth/access_token?client_id={app-id}&client_secret={app-secret}&code={code-from-facebook}&redirect_uri=http://{url}/login-redirect?myExtraParameter={value-extracted-in-step-2}

Additional 4 parameter passed in step 1 after the first 3 query parameter will be ignored. Also make 2 sure to not include any invalid characters 1 in your query parameter (see this for more information).

More Related questions