Skip to content

Commit 1a1e3c8

Browse files
committed
fix(auth): keep next parameter over SAML auth
It suffers the same issues as OpenID, so reuse the code. See python-social-auth/social-app-django#481
1 parent 2c5c569 commit 1a1e3c8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

weblate/accounts/views.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@
159159
if TYPE_CHECKING:
160160
from weblate.auth.models import AuthenticatedHttpRequest
161161

162+
AUTHID_SALT = "weblate.authid"
163+
AUTHID_MAX_AGE = 600
164+
162165
CONTACT_TEMPLATE = """
163166
Message from %(name)s <%(email)s>:
164167
@@ -1329,15 +1332,17 @@ def social_auth(request: AuthenticatedHttpRequest, backend: str):
13291332
except MissingBackend:
13301333
msg = "Backend not found"
13311334
raise Http404(msg) from None
1332-
# Store session ID for OpenID based auth. The session cookies will not be sent
1333-
# on returning POST request due to SameSite cookie policy
1334-
if isinstance(request.backend, OpenIdAuth):
1335+
1336+
# Store session ID for OpenID or SAML based auth. The session cookies will
1337+
# not be sent on returning POST request due to SameSite cookie policy
1338+
if isinstance(request.backend, OpenIdAuth) or backend == "saml":
13351339
request.backend.redirect_uri += "?authid={}".format(
13361340
dumps(
13371341
(request.session.session_key, get_ip_address(request)),
1338-
salt="weblate.authid",
1342+
salt=AUTHID_SALT,
13391343
)
13401344
)
1345+
13411346
try:
13421347
return do_auth(request.backend, redirect_name=REDIRECT_FIELD_NAME)
13431348
except AuthException as error:
@@ -1417,7 +1422,9 @@ def social_complete(request: AuthenticatedHttpRequest, backend: str): # noqa: C
14171422
if "authid" in request.GET:
14181423
try:
14191424
session_key, ip_address = loads(
1420-
request.GET["authid"], max_age=600, salt="weblate.authid"
1425+
request.GET["authid"],
1426+
max_age=AUTHID_MAX_AGE,
1427+
salt=AUTHID_SALT,
14211428
)
14221429
except (BadSignature, SignatureExpired):
14231430
return auth_redirect_token(request)

0 commit comments

Comments
 (0)