ebay.py 832 B

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