Skip to content

Commit 253d1c1

Browse files
committed
Make the relay_state optional in the response.
If relay_state isn't part of the outgoing request, it won't come back as a response. In that case, the code wouldn't work.
1 parent f22ab44 commit 253d1c1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

flask_saml2/sp/sp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ServiceProvider:
3737
def login_successful(
3838
self,
3939
auth_data: AuthData,
40-
relay_state: str,
40+
redirect_to: str,
4141
) -> Response:
4242
""" Called when a user is successfully logged on.
4343
Subclasses should override this if they want to do more
@@ -49,7 +49,9 @@ def login_successful(
4949
but they *must* call ``super()``.
5050
"""
5151
self.set_auth_data_in_session(auth_data)
52-
return redirect(relay_state)
52+
if not redirect_to:
53+
redirect_to = self.get_login_return_url()
54+
return redirect(redirect_to)
5355

5456
# Service provider configuration
5557

@@ -168,7 +170,7 @@ def get_login_return_url(self) -> Optional[str]:
168170
for url in urls:
169171
if url is None:
170172
continue
171-
url = self.make_absolute_url(url)
173+
172174
if self.is_valid_redirect_url(url):
173175
return url
174176

flask_saml2/sp/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def do_logout(self, handler):
7979
class AssertionConsumer(SAML2View):
8080
def post(self):
8181
saml_request = request.form['SAMLResponse']
82-
relay_state = request.form['RelayState']
82+
relay_state = request.form.get('RelayState')
8383

8484
for handler in self.sp.get_idp_handlers():
8585
try:

0 commit comments

Comments
 (0)