Skip to content

Commit

Permalink
Re-add redirect_to_auth_server() for compatibility with v1.x
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Oct 24, 2024
1 parent b856a0c commit d0cac91
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 24 additions & 5 deletions flask_oidc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,34 @@ def require_login(self, view_func):
@wraps(view_func)
def decorated(*args, **kwargs):
if not self.user_loggedin:
redirect_uri = "{login}?next={here}".format(
login=url_for("oidc_auth.login"),
here=quote_plus(request.url),
)
return redirect(redirect_uri)
return self.redirect_to_auth_server()
return view_func(*args, **kwargs)

return decorated

def redirect_to_auth_server(self, destination=None, customstate=None):
"""
Redirect to the IdP.
:param destination: The page that the user was going to,
before we noticed they weren't logged in.
:type destination: Url to return the client to if a custom handler is
not used. Not available with custom callback.
:param customstate: Ignored, left here for compatibility.
:returns: A redirect response to start the login process.
"""
if customstate is not None:
warnings.warn(
"The customstate argument of redirect_to_auth_server is ignored.",
DeprecationWarning,
stacklevel=2,
)
redirect_uri = "{login}?next={here}".format(
login=url_for("oidc_auth.login"),
here=quote_plus(destination or request.url),
)
return redirect(redirect_uri)

def logout(self, return_to=None):
"""
Request the browser to please forget the cookie we set, to clear the
Expand Down
8 changes: 8 additions & 0 deletions tests/test_flask_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ def test_bad_token(client):
assert "Internal Server Error" in resp.get_data(as_text=True)


def test_redirect_obsolete_argument(test_app):
with test_app.test_request_context(path="/somewhere"):
with pytest.warns(DeprecationWarning):
resp = test_app.oidc_ext.redirect_to_auth_server(None, "dummy")
assert resp.status_code == 302
assert resp.location == "/login?next=http%3A%2F%2Flocalhost%2Fsomewhere"


def test_user_getinfo(test_app, client, dummy_token):
user_info = {"nickname": "dummy"}
with test_app.test_request_context(path="/somewhere"):
Expand Down

0 comments on commit d0cac91

Please sign in to comment.