Как настроить Django social Auth для Google OAuth2, чтобы можно было войти только с адресом электронной почты компании
На данный момент любой пользователь с учетной записью gmail может войти в мое приложение django, тогда как я хочу ограничить пользователя с доменом компании, который может войти только через gmail в мое приложение.
example:
Allowed:
akashrathor@example.com
xyz@xyzcompany.com
abcdefgh@abccompany.com
not allowed:
abcd@gmail.com
насколько мой settings.py установлен как:
INSTALLED_APPS = [
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
]
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details'
)
SOCIAL_AUTH_DISCONNECT_PIPELINE = (
'social.pipeline.disconnect.get_entries',
'social.pipeline.disconnect.revoke_tokens',
'social.pipeline.disconnect.disconnect'
)
AUTHENTICATION_BACKENDS = [
'allauth.account.auth_backends.AuthenticationBackend',
]
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
}
}
}
SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
my urls.py
from django.urls import path,include
from django.contrib.auth.views import LogoutView
urlpatterns = [
path('accounts/', include('allauth.urls')),
path('logout', LogoutView.as_view(),name="logout"),
]