]> projects.mako.cc - twitter-api-cdsw/blob - requests_oauthlib/compliance_fixes/linkedin.py
reverted the encoding fix that tommy made in lieu of a different crazy hack
[twitter-api-cdsw] / requests_oauthlib / compliance_fixes / linkedin.py
1 from json import loads, dumps
2
3 from oauthlib.common import add_params_to_uri, to_unicode
4
5
6 def linkedin_compliance_fix(session):
7
8     def _missing_token_type(r):
9         token = loads(r.text)
10         token['token_type'] = 'Bearer'
11         r._content = to_unicode(dumps(token)).encode('UTF-8')
12         return r
13
14     def _non_compliant_param_name(url, headers, data):
15         token = [('oauth2_access_token', session._client.access_token)]
16         url = add_params_to_uri(url, token)
17         return url, headers, data
18
19     session._client.default_token_placement = 'query'
20     session.register_compliance_hook('access_token_response',
21                                      _missing_token_type)
22     session.register_compliance_hook('protected_request',
23                                      _non_compliant_param_name)
24     return session

Benjamin Mako Hill || Want to submit a patch?