ebay.py 890 B

1234567891011121314151617181920212223
  1. import json
  2. from oauthlib.common import to_unicode
  3. def ebay_compliance_fix(session):
  4. def _compliance_fix(response):
  5. token = json.loads(response.text)
  6. # eBay responds with non-compliant token types.
  7. # https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
  8. # https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html
  9. # Modify these to be "Bearer".
  10. if token.get("token_type") in ["Application Access Token", "User Access Token"]:
  11. token["token_type"] = "Bearer"
  12. fixed_token = json.dumps(token)
  13. response._content = to_unicode(fixed_token).encode("utf-8")
  14. return response
  15. session.register_compliance_hook("access_token_response", _compliance_fix)
  16. session.register_compliance_hook("refresh_token_response", _compliance_fix)
  17. return session