mirror of
https://github.com/rembo10/headphones.git
synced 2026-07-22 08:53:59 +01:00
update requests_oauthlib
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
# ruff: noqa: F401
|
||||
from .facebook import facebook_compliance_fix
|
||||
from .fitbit import fitbit_compliance_fix
|
||||
from .linkedin import linkedin_compliance_fix
|
||||
from .slack import slack_compliance_fix
|
||||
from .instagram import instagram_compliance_fix
|
||||
from .mailchimp import mailchimp_compliance_fix
|
||||
from .weibo import weibo_compliance_fix
|
||||
from .plentymarkets import plentymarkets_compliance_fix
|
||||
from .ebay import ebay_compliance_fix
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import json
|
||||
|
||||
from oauthlib.common import to_unicode
|
||||
|
||||
|
||||
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 = to_unicode(fixed_token).encode("utf-8")
|
||||
r._content = fixed_token.encode()
|
||||
return r
|
||||
|
||||
session._client_default_token_placement = "query"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import json
|
||||
|
||||
|
||||
def ebay_compliance_fix(session):
|
||||
def _compliance_fix(response):
|
||||
token = json.loads(response.text)
|
||||
|
||||
# eBay responds with non-compliant token types.
|
||||
# https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
|
||||
# https://developer.ebay.com/api-docs/static/oauth-auth-code-grant-request.html
|
||||
# Modify these to be "Bearer".
|
||||
if token.get("token_type") in ["Application Access Token", "User Access Token"]:
|
||||
token["token_type"] = "Bearer"
|
||||
fixed_token = json.dumps(token)
|
||||
response._content = fixed_token.encode()
|
||||
|
||||
return response
|
||||
|
||||
session.register_compliance_hook("access_token_response", _compliance_fix)
|
||||
session.register_compliance_hook("refresh_token_response", _compliance_fix)
|
||||
|
||||
return session
|
||||
@@ -1,11 +1,5 @@
|
||||
from json import dumps
|
||||
|
||||
try:
|
||||
from urlparse import parse_qsl
|
||||
except ImportError:
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
from oauthlib.common import to_unicode
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
|
||||
def facebook_compliance_fix(session):
|
||||
@@ -26,7 +20,7 @@ def facebook_compliance_fix(session):
|
||||
if expires is not None:
|
||||
token["expires_in"] = expires
|
||||
token["token_type"] = "Bearer"
|
||||
r._content = to_unicode(dumps(token)).encode("UTF-8")
|
||||
r._content = dumps(token).encode()
|
||||
return r
|
||||
|
||||
session.register_compliance_hook("access_token_response", _compliance_fix)
|
||||
|
||||
@@ -8,8 +8,6 @@ MissingTokenError.
|
||||
|
||||
from json import loads, dumps
|
||||
|
||||
from oauthlib.common import to_unicode
|
||||
|
||||
|
||||
def fitbit_compliance_fix(session):
|
||||
def _missing_error(r):
|
||||
@@ -17,7 +15,7 @@ def fitbit_compliance_fix(session):
|
||||
if "errors" in token:
|
||||
# Set the error to the first one we have
|
||||
token["error"] = token["errors"][0]["errorType"]
|
||||
r._content = to_unicode(dumps(token)).encode("UTF-8")
|
||||
r._content = dumps(token).encode()
|
||||
return r
|
||||
|
||||
session.register_compliance_hook("access_token_response", _missing_error)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
try:
|
||||
from urlparse import urlparse, parse_qs
|
||||
except ImportError:
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
from oauthlib.common import add_params_to_uri
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
from json import loads, dumps
|
||||
|
||||
from oauthlib.common import add_params_to_uri, to_unicode
|
||||
|
||||
|
||||
def linkedin_compliance_fix(session):
|
||||
def _missing_token_type(r):
|
||||
token = loads(r.text)
|
||||
token["token_type"] = "Bearer"
|
||||
r._content = to_unicode(dumps(token)).encode("UTF-8")
|
||||
return r
|
||||
|
||||
def _non_compliant_param_name(url, headers, data):
|
||||
token = [("oauth2_access_token", session.access_token)]
|
||||
url = add_params_to_uri(url, token)
|
||||
return url, headers, data
|
||||
|
||||
session._client.default_token_placement = "query"
|
||||
session.register_compliance_hook("access_token_response", _missing_token_type)
|
||||
session.register_compliance_hook("protected_request", _non_compliant_param_name)
|
||||
return session
|
||||
@@ -1,21 +1,19 @@
|
||||
import json
|
||||
|
||||
from oauthlib.common import to_unicode
|
||||
|
||||
|
||||
def mailchimp_compliance_fix(session):
|
||||
def _null_scope(r):
|
||||
token = json.loads(r.text)
|
||||
if "scope" in token and token["scope"] is None:
|
||||
token.pop("scope")
|
||||
r._content = to_unicode(json.dumps(token)).encode("utf-8")
|
||||
r._content = json.dumps(token).encode()
|
||||
return r
|
||||
|
||||
def _non_zero_expiration(r):
|
||||
token = json.loads(r.text)
|
||||
if "expires_in" in token and token["expires_in"] == 0:
|
||||
token["expires_in"] = 3600
|
||||
r._content = to_unicode(json.dumps(token)).encode("utf-8")
|
||||
r._content = json.dumps(token).encode()
|
||||
return r
|
||||
|
||||
session.register_compliance_hook("access_token_response", _null_scope)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
from json import dumps, loads
|
||||
import re
|
||||
|
||||
from oauthlib.common import to_unicode
|
||||
|
||||
|
||||
def plentymarkets_compliance_fix(session):
|
||||
def _to_snake_case(n):
|
||||
@@ -22,7 +20,7 @@ def plentymarkets_compliance_fix(session):
|
||||
for k, v in token.items():
|
||||
fixed_token[_to_snake_case(k)] = v
|
||||
|
||||
r._content = to_unicode(dumps(fixed_token)).encode("UTF-8")
|
||||
r._content = dumps(fixed_token).encode()
|
||||
return r
|
||||
|
||||
session.register_compliance_hook("access_token_response", _compliance_fix)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
try:
|
||||
from urlparse import urlparse, parse_qs
|
||||
except ImportError:
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
from oauthlib.common import add_params_to_uri
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from json import loads, dumps
|
||||
|
||||
from oauthlib.common import to_unicode
|
||||
|
||||
|
||||
def weibo_compliance_fix(session):
|
||||
def _missing_token_type(r):
|
||||
token = loads(r.text)
|
||||
token["token_type"] = "Bearer"
|
||||
r._content = to_unicode(dumps(token)).encode("UTF-8")
|
||||
r._content = dumps(token).encode()
|
||||
return r
|
||||
|
||||
session._client.default_token_placement = "query"
|
||||
|
||||
Reference in New Issue
Block a user