backend: Handle GitHub authentication failure.

In case of AuthFailed exception return None.
This commit is contained in:
Umair Khan
2017-02-28 15:58:03 +05:00
committed by Tim Abbott
parent f140810ad9
commit 802de53ede
2 changed files with 25 additions and 1 deletions

View File

@@ -178,6 +178,14 @@ class SocialAuthMixin(ZulipAuthMixin):
return redirect_and_log_into_subdomain(realm, full_name, email_address)
def auth_complete(self, *args, **kwargs):
# type: (*Any, **Any) -> Optional[HttpResponse]
try:
# Call the auth_complete method of BaseOAuth2 is Python Social Auth
return super(SocialAuthMixin, self).auth_complete(*args, **kwargs) # type: ignore
except AuthFailed:
return None
class ZulipDummyBackend(ZulipAuthMixin):
"""
Used when we want to log you in but we don't know which backend to use.
@@ -425,7 +433,11 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
org_name = settings.SOCIAL_AUTH_GITHUB_ORG_NAME
if (team_id is None and org_name is None):
user_profile = GithubOAuth2.do_auth(self, *args, **kwargs)
try:
user_profile = GithubOAuth2.do_auth(self, *args, **kwargs)
except AuthFailed:
logging.info("User authentication failed.")
user_profile = None
elif (team_id):
backend = GithubTeamOAuth2(self.strategy, self.redirect_uri)