Skip to content

Commit d38555d

Browse files
jaclarkescotttrinh
andauthored
Return json from magic code authenticate endpoint if no callback_url is given (#9012)
Match the behaviour of the email+password authenticate endpoint, and return a json response if the `callback_url` is not passed to the magic code authenticate endpoint. --------- Co-authored-by: Scott Trinh <[email protected]>
1 parent 87cdbad commit d38555d

File tree

1 file changed

+20
-7
lines changed
  • edb/server/protocol/auth_ext

1 file changed

+20
-7
lines changed

edb/server/protocol/auth_ext/http.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,15 +1710,21 @@ async def handle_magic_link_authenticate(
17101710
data = self._get_data_from_request(request)
17111711

17121712
_check_keyset(
1713-
data, {"email", "code", "callback_url", "challenge"}
1713+
data, {"email", "code", "challenge"}
17141714
)
17151715

17161716
email = data["email"]
17171717
code_str = data["code"]
1718-
callback_url = data["callback_url"]
17191718
challenge = data["challenge"]
17201719

1721-
if not self._is_url_allowed(callback_url):
1720+
maybe_callback_url = cast(
1721+
Optional[str], data.get("callback_url")
1722+
)
1723+
1724+
if (
1725+
maybe_callback_url and
1726+
not self._is_url_allowed(maybe_callback_url)
1727+
):
17221728
raise errors.InvalidData(
17231729
"Callback URL does not match any allowed URLs.",
17241730
)
@@ -1761,10 +1767,17 @@ async def handle_magic_link_authenticate(
17611767
datetime.datetime.now(datetime.timezone.utc),
17621768
)
17631769

1764-
return self._try_redirect(
1765-
response,
1766-
util.join_url_params(callback_url, {"code": auth_code}),
1767-
)
1770+
response_dict = {"code": auth_code}
1771+
1772+
if maybe_callback_url:
1773+
return self._try_redirect(
1774+
response,
1775+
util.join_url_params(maybe_callback_url, response_dict),
1776+
)
1777+
else:
1778+
response.status = http.HTTPStatus.OK
1779+
response.content_type = b"application/json"
1780+
response.body = json.dumps(response_dict).encode()
17681781

17691782
except Exception as ex:
17701783
redirect_on_failure = _maybe_get_search_param(

0 commit comments

Comments
 (0)