velruse icon indicating copy to clipboard operation
velruse copied to clipboard

Updae Facebook provider because they now return JSON for the access_token

Open antoineleclair opened this issue 7 years ago • 2 comments

From their changelog:

[Oauth Access Token] Format - The response format of https://www.facebook.com/v2.3/oauth/access_token returned when you exchange a code for an access_token now return valid JSON instead of being URL encoded. The new format of this response is {"access_token": {TOKEN}, "token_type":{TYPE}, "expires_in":{TIME}}. We made this update to be compliant with section 5.1 of RFC 6749.

Otherwise the Facebook provider is now broken since they stopped supporting the old way.

antoineleclair avatar Mar 27 '17 20:03 antoineleclair

@antoineleclair Hello, it’s been a while!

The above fix today caused the following:

  File "/…/velruse/providers/facebook.py", line 121, in callback
    access_token = r.json()['access_token']
KeyError: 'access_token'

Looking at the response body though, r.json() gives me a dictionary of the following form:

{
    'access_token': 'EA…ZD',
    'token_type': 'bearer',
    'expires_in': 5180555
}

Should 'bearer' not be 'Bearer' though? When I use the following code, oddly enough it works:

rbody = r.json()
access_token = rbody['access_token']

jenstroeger avatar Nov 02 '17 20:11 jenstroeger

Also, FB URL has changed to https://www.facebook.com/v3.0/dialog/oauth. References see here and here.

jenstroeger avatar May 31 '18 00:05 jenstroeger