Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/social_auth/backends/asana.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
and put into sentry.conf.py
"""

from urllib.parse import parse_qsl, urlencode

import requests

from social_auth.backends import BaseOAuth2, OAuthBackend
Expand Down Expand Up @@ -56,6 +58,48 @@ def user_data(self, access_token, *args, **kwargs):
except ValueError:
return None

def auth_url(self):
if self.STATE_PARAMETER or self.REDIRECT_STATE:
# Store state in session for further request validation. The state
# value is passed as state parameter (as specified in OAuth2 spec),
# but also added to redirect_uri, that way we can still verify the
# request if the provider doesn't implement the state parameter.
# Reuse token if any.
name = self.AUTH_BACKEND.name + "_state"
state = self.request.session.get(name) or self.state_token()
self.request.session[self.AUTH_BACKEND.name + "_state"] = state
else:
state = None

params = self.auth_params(state)
params.update(self.get_scope_argument())
params.update(self.auth_extra_arguments())

query_string = self._get_safe_query_string()
return self.AUTHORIZATION_URL + "?" + urlencode(params) + query_string

def _get_safe_query_string(self):
"""
Returns filtered query string without client_id parameter.
"""

query_string = self.request.META.get("QUERY_STRING", "")
if not query_string:
return ""

parsed_params = parse_qsl(query_string, keep_blank_values=True)
safe_params = []

for param_name, param_value in parsed_params:
# Remove client_id parameter
if param_name.lower() != "client_id":
safe_params.append((param_name, param_value))

if safe_params:
return "&" + urlencode(safe_params)
else:
return ""
Comment on lines +81 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than implement this just for asana, I think it'd be fine to make the change on the base class (BaseOAuth2). The other implementations are both deprecated, and it'd avoid us having to redeclare auth_url.


def auth_complete(self, *args, **kwargs):
"""Completes logging process, must return user instance"""
self.process_error(self.data)
Expand Down
Loading