forked from cvat-ai/cvat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Social authentication] Remove server part && tests (cvat-ai#5691)
- Loading branch information
1 parent
f7838b1
commit 3066c6e
Showing
28 changed files
with
34 additions
and
947 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,12 @@ | ||
# Copyright (C) 2022 CVAT.ai Corporation | ||
# Copyright (C) 2022-2023 CVAT.ai Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.http import HttpResponseRedirect, HttpResponseBadRequest | ||
from django.http import HttpResponseRedirect | ||
from django.conf import settings | ||
|
||
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter | ||
from allauth.account.adapter import DefaultAccountAdapter | ||
from allauth.socialaccount.providers.amazon_cognito.views import AmazonCognitoOAuth2Adapter | ||
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter | ||
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter | ||
from allauth.exceptions import ImmediateHttpResponse | ||
from allauth.account.utils import filter_users_by_email | ||
|
||
UserModel = get_user_model() | ||
|
||
class DefaultAccountAdapterEx(DefaultAccountAdapter): | ||
def respond_email_verification_sent(self, request, user): | ||
return HttpResponseRedirect(settings.ACCOUNT_EMAIL_VERIFICATION_SENT_REDIRECT_URL) | ||
|
||
class SocialAccountAdapterEx(DefaultSocialAccountAdapter): | ||
def pre_social_login(self, request, sociallogin): | ||
""" | ||
Invoked just after a user successfully authenticates via a | ||
social provider, but before the login is actually processed | ||
(and before the pre_social_login signal is emitted). | ||
""" | ||
if sociallogin.is_existing: | ||
return | ||
|
||
if not sociallogin.email_addresses: | ||
raise ImmediateHttpResponse(response=HttpResponseBadRequest('No email is associated with this social account')) | ||
|
||
users = filter_users_by_email(sociallogin.user.email) | ||
if len(users) > 1: | ||
raise ImmediateHttpResponse(HttpResponseBadRequest(f'Cannot connect account with ${sociallogin.user.email} email.')) | ||
elif users: | ||
sociallogin.connect(request, users[0]) | ||
return | ||
|
||
class GitHubAdapter(GitHubOAuth2Adapter): | ||
|
||
def get_callback_url(self, request, app): | ||
return settings.GITHUB_CALLBACK_URL | ||
|
||
class GoogleAdapter(GoogleOAuth2Adapter): | ||
|
||
def get_callback_url(self, request, app): | ||
return settings.GOOGLE_CALLBACK_URL | ||
|
||
class AmazonCognitoOAuth2AdapterEx(AmazonCognitoOAuth2Adapter): | ||
def get_callback_url(self, request, app): | ||
return settings.AMAZON_COGNITO_REDIRECT_URI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.