Skip to content

Commit 4ab3e59

Browse files
committed
add instagram compliance fix
1 parent 1495328 commit 4ab3e59

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
try:
2+
from urlparse import urlparse, parse_qs
3+
except ImportError:
4+
from urllib.parse import urlparse, parse_qs
5+
6+
from oauthlib.common import add_params_to_uri
7+
8+
9+
def instagram_compliance_fix(session):
10+
def _non_compliant_param_name(url, headers, data):
11+
# If the user has already specified the token, either in the URL
12+
# or in a data dictionary, then there's nothing to do.
13+
# If the specified token is different from ``session.access_token``,
14+
# we assume the user intends to override the access token.
15+
url_query = dict(parse_qs(urlparse(url).query))
16+
token = url_query.get("token")
17+
if not token and isinstance(data, dict):
18+
token = data.get("token")
19+
20+
if token:
21+
# Nothing to do, just return.
22+
return url, headers, data
23+
24+
token = [('access_token', session.access_token)]
25+
url = add_params_to_uri(url, token)
26+
return url, headers, data
27+
28+
session.register_compliance_hook(
29+
'protected_request', _non_compliant_param_name)
30+
return session

0 commit comments

Comments
 (0)