Skip to content

Commit 553e953

Browse files
authored
Revert "Revert embedded link (#262)" (#269)
This reverts commit b544883.
1 parent 4ae5ab4 commit 553e953

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

.vscode/settings.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,4 @@
33
"python.testing.pytestArgs": [
44
"tests"
55
],
6-
"workbench.colorCustomizations": {
7-
"activityBar.background": "#4D1C3B",
8-
"titleBar.activeBackground": "#6B2752",
9-
"titleBar.activeForeground": "#FDF8FB"
10-
},
116
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,10 @@ pending_ref = resp["pendingRef"]
852852

853853
# Note 1: The generate code/link functions, work only for test users, will not work for regular users.
854854
# Note 2: In case of testing sign-in / sign-up operations with test users, need to make sure to generate the code prior calling the sign-in / sign-up operations.
855+
856+
# Embedded links can be created to directly receive a verifiable token without sending it.
857+
# This token can then be verified using the magic link 'verify' function, either directly or through a flow.
858+
token, err = descope_client.mgmt.user.generate_embedded_link("[email protected]", {"key1":"value1"})
855859
```
856860

857861
## API Rate Limits

descope/management/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class MgmtV1:
3333
user_generate_otp_for_test_path = "/v1/mgmt/tests/generate/otp"
3434
user_generate_magic_link_for_test_path = "/v1/mgmt/tests/generate/magiclink"
3535
user_generate_enchanted_link_for_test_path = "/v1/mgmt/tests/generate/enchantedlink"
36+
user_generate_embedded_link_path = "/v1/mgmt/user/signin/embeddedlink"
3637

3738
# access key
3839
access_key_create_path = "/v1/mgmt/accesskey/create"

descope/management/user.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,28 @@ def generate_enchanted_link_for_test_user(
923923
)
924924
return response.json()
925925

926+
def generate_embedded_link(self, login_id: str, custom_claims: dict = None) -> str:
927+
"""
928+
Generate Embedded Link for the given user login ID.
929+
The return value is a token that can be verified via magic link, or using flows
930+
931+
Args:
932+
login_id (str): The login ID of the user to authenticate with.
933+
custom_claims (dict): Additional claims to place on the jwt after verification
934+
935+
Return value (str):
936+
Return the token to be used in verification process
937+
938+
Raise:
939+
AuthException: raised if the operation fails
940+
"""
941+
response = self._auth.do_post(
942+
MgmtV1.user_generate_embedded_link_path,
943+
{"loginId": login_id, "customClaims": custom_claims},
944+
pswd=self._auth.management_key,
945+
)
946+
return response.json()["token"]
947+
926948
@staticmethod
927949
def _compose_create_body(
928950
login_id: str,

tests/management/test_user.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,37 @@ def test_generate_enchanted_link_for_test_user(self):
12301230
verify=True,
12311231
timeout=DEFAULT_TIMEOUT_SECONDS,
12321232
)
1233+
1234+
def test_generate_embedded_link(self):
1235+
# Test failed flows
1236+
with patch("requests.post") as mock_post:
1237+
mock_post.return_value.ok = False
1238+
self.assertRaises(
1239+
AuthException, self.client.mgmt.user.generate_embedded_link, "login-id"
1240+
)
1241+
1242+
# Test success flow
1243+
with patch("requests.post") as mock_post:
1244+
network_resp = mock.Mock()
1245+
network_resp.ok = True
1246+
network_resp.json.return_value = json.loads("""{"token": "some-token"}""")
1247+
mock_post.return_value = network_resp
1248+
resp = self.client.mgmt.user.generate_embedded_link(
1249+
"login-id", {"k1": "v1"}
1250+
)
1251+
self.assertEqual(resp, "some-token")
1252+
mock_post.assert_called_with(
1253+
f"{common.DEFAULT_BASE_URL}{MgmtV1.user_generate_embedded_link_path}",
1254+
headers={
1255+
**common.default_headers,
1256+
"Authorization": f"Bearer {self.dummy_project_id}:{self.dummy_management_key}",
1257+
},
1258+
json={
1259+
"loginId": "login-id",
1260+
"customClaims": {"k1": "v1"},
1261+
},
1262+
allow_redirects=False,
1263+
verify=True,
1264+
params=None,
1265+
timeout=DEFAULT_TIMEOUT_SECONDS,
1266+
)

0 commit comments

Comments
 (0)