Skip to content

Commit 22d3969

Browse files
committed
🎉 Make social auth exceptions configurable
1 parent 1ba1122 commit 22d3969

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

dojo/middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ def __call__(self, request):
8383
class CustomSocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
8484
def process_exception(self, request, exception):
8585
if isinstance(exception, requests.exceptions.RequestException):
86-
messages.error(request, "Please use the standard login below.")
86+
messages.error(request, settings.SOCIAL_AUTH_EXCEPTION_MESSAGE["SOCIAL_AUTH_EXCEPTION_MESSAGE_REQUEST_EXCEPTION"])
8787
return redirect("/login?force_login_form")
8888
if isinstance(exception, AuthCanceled):
89-
messages.warning(request, "Social login was canceled. Please try again or use the standard login.")
89+
messages.warning(request, settings.SOCIAL_AUTH_EXCEPTION_MESSAGE["SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_CANCELED"])
9090
return redirect("/login?force_login_form")
9191
if isinstance(exception, AuthFailed):
92-
messages.error(request, "Social login failed. Please try again or use the standard login.")
92+
messages.error(request, settings.SOCIAL_AUTH_EXCEPTION_MESSAGE["SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FAILED"])
9393
return redirect("/login?force_login_form")
9494
if isinstance(exception, AuthForbidden):
95-
messages.error(request, "You are not authorized to log in via this method. Please contact support or use the standard login.")
95+
messages.error(request, settings.SOCIAL_AUTH_EXCEPTION_MESSAGE["SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FORBIDDEN"])
9696
return redirect("/login?force_login_form")
9797
return super().process_exception(request, exception)
9898

dojo/settings/settings.dist.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@
173173
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_KEY=(str, ""),
174174
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_SECRET=(str, ""),
175175
DD_SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL=(bool, True),
176+
DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_REQUEST_EXCEPTION=(str, "Please use the standard login below."),
177+
DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_CANCELED=(str, "Social login was canceled. Please try again or use the standard login."),
178+
DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FAILED=(str, "Social login failed. Please try again or use the standard login."),
179+
DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FORBIDDEN=(str, "You are not authorized to log in via this method. Please contact support or use the standard login."),
176180
DD_SAML2_ENABLED=(bool, False),
177181
# Allows to override default SAML authentication backend. Check https://djangosaml2.readthedocs.io/contents/setup.html#custom-user-attributes-processing
178182
DD_SAML2_AUTHENTICATION_BACKENDS=(str, "djangosaml2.backends.Saml2Backend"),
@@ -643,6 +647,13 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
643647
if value := env("DD_SOCIAL_AUTH_OIDC_LOGIN_BUTTON_TEXT"):
644648
SOCIAL_AUTH_OIDC_LOGIN_BUTTON_TEXT = value
645649

650+
SOCIAL_AUTH_EXCEPTION_MESSAGE = {
651+
"SOCIAL_AUTH_EXCEPTION_MESSAGE_REQUEST_EXCEPTION": env("DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_REQUEST_EXCEPTION"),
652+
"SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_CANCELED": env("DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_CANCELED"),
653+
"SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FAILED": env("DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FAILED"),
654+
"SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FORBIDDEN": env("DD_SOCIAL_AUTH_EXCEPTION_MESSAGE_AUTH_FORBIDDEN"),
655+
}
656+
646657
AUTH0_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_AUTH0_OAUTH2_ENABLED")
647658
SOCIAL_AUTH_AUTH0_KEY = env("DD_SOCIAL_AUTH_AUTH0_KEY")
648659
SOCIAL_AUTH_AUTH0_SECRET = env("DD_SOCIAL_AUTH_AUTH0_SECRET")

0 commit comments

Comments
 (0)