Update requests-oauthlib-1.3.0

This commit is contained in:
JonnyWong16 2021-10-14 23:47:27 -07:00
parent e55576fd80
commit f165d2d080
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
15 changed files with 552 additions and 257 deletions

View file

@ -1,4 +1,5 @@
from json import dumps
try:
from urlparse import parse_qsl
except ImportError:
@ -8,26 +9,25 @@ from oauthlib.common import to_unicode
def facebook_compliance_fix(session):
def _compliance_fix(r):
# if Facebook claims to be sending us json, let's trust them.
if 'application/json' in r.headers.get('content-type', {}):
if "application/json" in r.headers.get("content-type", {}):
return r
# Facebook returns a content-type of text/plain when sending their
# x-www-form-urlencoded responses, along with a 200. If not, let's
# assume we're getting JSON and bail on the fix.
if 'text/plain' in r.headers.get('content-type', {}) and r.status_code == 200:
if "text/plain" in r.headers.get("content-type", {}) and r.status_code == 200:
token = dict(parse_qsl(r.text, keep_blank_values=True))
else:
return r
expires = token.get('expires')
expires = token.get("expires")
if expires is not None:
token['expires_in'] = expires
token['token_type'] = 'Bearer'
r._content = to_unicode(dumps(token)).encode('UTF-8')
token["expires_in"] = expires
token["token_type"] = "Bearer"
r._content = to_unicode(dumps(token)).encode("UTF-8")
return r
session.register_compliance_hook('access_token_response', _compliance_fix)
session.register_compliance_hook("access_token_response", _compliance_fix)
return session