Skip to content

Commit

Permalink
Fixes redirect after login for JSON requests
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
cuducos committed Jun 30, 2024
1 parent 99c1de9 commit 64723d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_simplelogin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def login(self):

if request.is_json:
# recommended to use `login_required(basic=True)` instead this
return self.basic_auth(destiny=redirect(destiny))
return self.basic_auth(redirect(destiny))

form = self._login_form()
ret_code = 200
Expand Down
11 changes: 11 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def test_positive_redirect_to_allowed_host(app):
assert response.status_code == 200


def test_positive_redirect_for_a_json_resquest(app):
app.config["ALLOWED_HOSTS"] = ["myothersite.com"]
with app.test_client() as client:
response = client.get(
url_for("simplelogin.login", next="https://myothersite.com/page"),
headers={"Content-Type": "application/json"},
follow_redirects=True,
)
assert response.status_code == 200


def test_is_logged_in(app, client, csrf_token_for):
client.get(url_for("simplelogin.login"))
assert not is_logged_in()
Expand Down

0 comments on commit 64723d3

Please sign in to comment.