Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions social_core/backends/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def get_apple_jwk(self, kid=None):

if kid:
return json.dumps([key for key in keys if key["kid"] == kid][0])
else:
return (json.dumps(key) for key in keys)
return (json.dumps(key) for key in keys)

def decode_id_token(self, id_token):
"""
Expand Down
3 changes: 1 addition & 2 deletions social_core/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def setting(self, name, default=None):
def start(self):
if self.uses_redirect():
return self.strategy.redirect(self.auth_url())
else:
return self.strategy.html(self.auth_html())
return self.strategy.html(self.auth_html())

def complete(self, *args, **kwargs):
return self.auth_complete(*args, **kwargs)
Expand Down
13 changes: 5 additions & 8 deletions social_core/backends/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ def get_user_id(self, details, response):
if self.setting("USE_UNIQUE_USER_ID", False):
if "sub" in response:
return response["sub"]
else:
return response["id"]
else:
return details["email"]
return response["id"]
return details["email"]

def get_user_details(self, response):
"""Return user details from Google API account"""
Expand Down Expand Up @@ -115,7 +113,7 @@ def auth_complete(self, *args, **kwargs):
)
self.process_error(response)
return self.do_auth(token, response=response, *args, **kwargs)
elif "code" in self.data: # Server-side workflow
if "code" in self.data: # Server-side workflow
response = self.request_access_token(
self.ACCESS_TOKEN_URL,
data=self.auth_complete_params(),
Expand All @@ -126,11 +124,10 @@ def auth_complete(self, *args, **kwargs):
return self.do_auth(
response["access_token"], response=response, *args, **kwargs
)
elif "id_token" in self.data: # Client-side workflow
if "id_token" in self.data: # Client-side workflow
token = self.data.get("id_token")
return self.do_auth(token, *args, **kwargs)
else:
raise AuthMissingParameter(self, "access_token, id_token, or code")
raise AuthMissingParameter(self, "access_token, id_token, or code")

def user_data(self, access_token, *args, **kwargs):
if "id_token" not in self.data:
Expand Down
3 changes: 1 addition & 2 deletions social_core/backends/mediawiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def force_unicode(value):
"""
if isinstance(value, str):
return value
else:
return str(value, "unicode-escape")
return str(value, "unicode-escape")


class MediaWiki(BaseOAuth1):
Expand Down
5 changes: 2 additions & 3 deletions social_core/backends/open_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def openid_url(self):
provider URL."""
if self.URL:
return self.URL
elif OPENID_ID_FIELD in self.data:
if OPENID_ID_FIELD in self.data:
return self.data[OPENID_ID_FIELD]
else:
raise AuthMissingParameter(self, OPENID_ID_FIELD)
raise AuthMissingParameter(self, OPENID_ID_FIELD)
3 changes: 1 addition & 2 deletions social_core/backends/qiita.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ def get_user_id(self, details, response):

if user_id is not None:
return str(user_id)
else:
raise AuthException("failed to get user id")
raise AuthException("failed to get user id")
2 changes: 1 addition & 1 deletion social_core/pipeline/social_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def associate_by_email(backend, details, user=None, *args, **kwargs):
users = list(backend.strategy.storage.user.get_users_by_email(email))
if len(users) == 0:
return None
elif len(users) > 1:
if len(users) > 1:
raise AuthException(
backend, "The given email address is associated with another account"
)
Expand Down
18 changes: 8 additions & 10 deletions social_core/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ def expiration_timedelta(self):
# expires is a datetime, return the remaining difference
expiry_time = datetime.fromtimestamp(expires, tz=timezone.utc)
return expiry_time - now
else:
# expires is the time to live seconds since creation,
# check against auth_time if present, otherwise return
# the value
auth_time = self.extra_data.get("auth_time")
if auth_time:
reference = datetime.fromtimestamp(auth_time, tz=timezone.utc)
return (reference + timedelta(seconds=expires)) - now
else:
return timedelta(seconds=expires)
# expires is the time to live seconds since creation,
# check against auth_time if present, otherwise return
# the value
auth_time = self.extra_data.get("auth_time")
if auth_time:
reference = datetime.fromtimestamp(auth_time, tz=timezone.utc)
return (reference + timedelta(seconds=expires)) - now
return timedelta(seconds=expires)

def expiration_datetime(self):
# backward compatible alias
Expand Down
4 changes: 2 additions & 2 deletions social_core/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def removeAssociation(self, server_url, handle):
def expiresIn(self, assoc):
if hasattr(assoc, "getExpiresIn"):
return assoc.getExpiresIn()
else: # python3-openid 3.0.2
return assoc.expiresIn
# python3-openid 3.0.2
return assoc.expiresIn

def getAssociation(self, server_url, handle=None):
"""Return stored association"""
Expand Down
12 changes: 5 additions & 7 deletions social_core/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def render(self, tpl=None, html=None, context=None):
context = context or {}
if tpl:
return self.render_template(tpl, context)
else:
return self.render_string(html, context)
return self.render_string(html, context)

def render_template(self, tpl, context):
raise NotImplementedError("Implement in subclass")
Expand Down Expand Up @@ -137,13 +136,12 @@ def validate_email(self, email, code):
verification_code = self.storage.code.get_code(code)
if not verification_code or verification_code.code != code:
return False
elif verification_code.email != email:
if verification_code.email != email:
return False
elif verification_code.verified:
if verification_code.verified:
return False
else:
verification_code.verify()
return True
verification_code.verify()
return True

def render_html(self, tpl=None, html=None, context=None):
"""Render given template or raw html with given context"""
Expand Down
6 changes: 2 additions & 4 deletions social_core/tests/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
def ask_for_password(strategy, *args, **kwargs):
if strategy.session_get("password"):
return {"password": strategy.session_get("password")}
else:
return strategy.redirect(strategy.build_absolute_uri("/password"))
return strategy.redirect(strategy.build_absolute_uri("/password"))


@partial
def ask_for_slug(strategy, *args, **kwargs):
if strategy.session_get("slug"):
return {"slug": strategy.session_get("slug")}
else:
return strategy.redirect(strategy.build_absolute_uri("/slug"))
return strategy.redirect(strategy.build_absolute_uri("/slug"))


def set_password(strategy, user, *args, **kwargs):
Expand Down
3 changes: 1 addition & 2 deletions social_core/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def get_social_auth(cls, provider, uid):
if cls._called_times == 2:
user = list(User.cache.values())[0]
return IntegrityErrorUserSocialAuth(user, provider, uid)
else:
return super().get_social_auth(provider, uid)
return super().get_social_auth(provider, uid)


class IntegrityErrorStorage(TestStorage):
Expand Down
10 changes: 4 additions & 6 deletions social_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def partial_pipeline_data(backend, user=None, partial_token=None, *args, **kwarg
kwargs.setdefault("request", request_data)
partial.extend_kwargs(kwargs)
return partial
else:
backend.strategy.clean_partial_pipeline(partial_token)
backend.strategy.clean_partial_pipeline(partial_token)


def build_absolute_uri(host_url, path=None):
Expand Down Expand Up @@ -242,10 +241,9 @@ def setting_url(backend, *names):
for name in names:
if is_url(name):
return name
else:
value = backend.setting(name)
if is_url(value):
return value
value = backend.setting(name)
if is_url(value):
return value


def handle_http_errors(func):
Expand Down
Loading