aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/requests-oauthlib/requests_oauthlib/compliance_fixes/douban.py
blob: c8b99c721e9bb09e3a0127bb90e09f53814d714c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import json


def douban_compliance_fix(session):
    def fix_token_type(r):
        token = json.loads(r.text)
        token.setdefault("token_type", "Bearer")
        fixed_token = json.dumps(token)
        r._content = fixed_token.encode()
        return r

    session._client_default_token_placement = "query"
    session.register_compliance_hook("access_token_response", fix_token_type)

    return session