Skip to content

Commit 3043814

Browse files
authored
Added support to set SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS (#429)
* Added support to set SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS * Added a redirect for /login * Fix lints * Fix lint
1 parent d6e234b commit 3043814

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@
547547
"description": "The client secret provided by the OpenID Connect provider.",
548548
"required": false
549549
},
550+
"SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS": {
551+
"description": "The list of additional redirect hosts allowed for social auth.",
552+
"required": false
553+
},
550554
"USERINFO_URL": {
551555
"description": "Provder endpoint where client sends requests for identity claims.",
552556
"required": false

authentication/urls.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
"""URL configurations for authentication"""
22

3-
from django.urls import re_path
3+
from django.urls import include, re_path, reverse_lazy
4+
from django.views.generic.base import RedirectView
45

56
from authentication.views import CustomLogoutView
67

78
urlpatterns = [
9+
re_path(r"", include("social_django.urls", namespace="social")),
10+
re_path(
11+
r"^login/$",
12+
RedirectView.as_view(
13+
url=reverse_lazy("social:begin", args=["ol-oidc"]), query_string=True
14+
),
15+
name="login",
16+
),
817
re_path(r"^logout/$", CustomLogoutView.as_view(), name="logout"),
918
]

open_discussions/settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,13 @@
225225

226226
SOCIAL_AUTH_LOGIN_REDIRECT_URL = "/"
227227
SOCIAL_AUTH_LOGIN_ERROR_URL = "login"
228-
SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS = [urlparse(SITE_BASE_URL).netloc]
228+
SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS = [
229+
*get_list_of_str(
230+
name="SOCIAL_AUTH_ALLOWED_REDIRECT_HOSTS",
231+
default=[],
232+
),
233+
urlparse(SITE_BASE_URL).netloc,
234+
]
229235

230236
SOCIAL_AUTH_PIPELINE = (
231237
# Checks if an admin user attempts to login/register while hijacking another user.

open_discussions/urls.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
urlpatterns = [ # noqa: RUF005
3535
re_path(r"^admin/", admin.site.urls),
3636
re_path(r"", include("authentication.urls")),
37-
re_path(r"", include("social_django.urls", namespace="social")),
3837
re_path(r"", include("channels.urls")),
3938
re_path(r"", include("profiles.urls")),
4039
re_path(r"", include("embedly.urls")),

0 commit comments

Comments
 (0)