codekingpro/portable-devtools
114k
1import json2 3 4def ebay_compliance_fix(session):5 def _compliance_fix(response):6 token = json.loads(response.text)7 8 # eBay responds with non-compliant token types.9 # https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html10 # https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html11 # Modify these to be "Bearer".12 if token.get("token_type") in ["Application Access Token", "User Access Token"]:13 token["token_type"] = "Bearer"14 fixed_token = json.dumps(token)15 response._content = fixed_token.encode()16 17 return response18 19 session.register_compliance_hook("access_token_response", _compliance_fix)20 session.register_compliance_hook("refresh_token_response", _compliance_fix)21 22 return session23 