Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non compliant param name update/fix for LinkedIn integration. #388

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions requests_oauthlib/compliance_fixes/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ def _missing_token_type(r):
return r

def _non_compliant_param_name(url, headers, data):
token = [("oauth2_access_token", session.access_token)]
url = add_params_to_uri(url, token)
if "&access_token=" in url:
url = url.replace("access_token", "oauth2_access_token")
else:
token = [("oauth2_access_token", session.access_token)]
url = add_params_to_uri(url, token)
return url, headers, data

session._client.default_token_placement = "query"
Expand Down
18 changes: 10 additions & 8 deletions requests_oauthlib/oauth2_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,19 +464,21 @@ def request(
if not is_secure_transport(url):
raise InsecureTransportError()
if self.token and not withhold_token:
log.debug(
"Invoking %d protected resource request hooks.",
len(self.compliance_hook["protected_request"]),
)
for hook in self.compliance_hook["protected_request"]:
log.debug("Invoking hook %s.", hook)
url, headers, data = hook(url, headers, data)

log.debug("Adding token %s to request.", self.token)
try:
url, headers, data = self._client.add_token(
url, http_method=method, body=data, headers=headers
)
# Moving this compliance hook invocation until after the access_token is added and handling the
# token venacular within the compliance hook.
log.debug(
"Invoking %d protected resource request hooks.",
len(self.compliance_hook["protected_request"]),
)
for hook in self.compliance_hook["protected_request"]:
log.debug("Invoking hook %s.", hook)
url, headers, data = hook(url, headers, data)

# Attempt to retrieve and save new access token if expired
except TokenExpiredError:
if self.auto_refresh_url:
Expand Down