Skip to content

Commit 184646d

Browse files
authored
Add find invitation by token method (#274)
1 parent 5e475a4 commit 184646d

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/test_user_management.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,18 @@ def test_get_invitation(self, mock_invitation, capture_and_mock_request):
10471047
assert url[0].endswith("user_management/invitations/invitation_ABCDE")
10481048
assert invitation["id"] == "invitation_ABCDE"
10491049

1050+
def test_find_invitation_by_token(self, mock_invitation, capture_and_mock_request):
1051+
url, request_kwargs = capture_and_mock_request("get", mock_invitation, 200)
1052+
1053+
invitation = self.user_management.find_invitation_by_token(
1054+
"Z1uX3RbwcIl5fIGJJJCXXisdI"
1055+
)
1056+
1057+
assert url[0].endswith(
1058+
"user_management/invitations/by_token/Z1uX3RbwcIl5fIGJJJCXXisdI"
1059+
)
1060+
assert invitation["token"] == "Z1uX3RbwcIl5fIGJJJCXXisdI"
1061+
10501062
def test_list_invitations_returns_metadata(
10511063
self,
10521064
mock_invitations,

workos/user_management.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
EMAIL_VERIFICATION_DETAIL_PATH = "user_management/email_verification/{0}"
5050
INVITATION_PATH = "user_management/invitations"
5151
INVITATION_DETAIL_PATH = "user_management/invitations/{0}"
52+
INVITATION_DETAIL_BY_TOKEN_PATH = "user_management/invitations/by_token/{0}"
5253
INVITATION_REVOKE_PATH = "user_management/invitations/{0}/revoke"
5354
PASSWORD_RESET_PATH = "user_management/password_reset"
5455
PASSWORD_RESET_DETAIL_PATH = "user_management/password_reset/{0}"
@@ -1205,6 +1206,26 @@ def get_invitation(self, invitation_id):
12051206

12061207
return WorkOSInvitation.construct_from_response(response).to_dict()
12071208

1209+
def find_invitation_by_token(self, invitation_token):
1210+
"""Get the details of an invitation.
1211+
1212+
Args:
1213+
invitation_token (str) - The token of the Invitation.
1214+
1215+
Returns:
1216+
dict: Invitation response from WorkOS.
1217+
"""
1218+
headers = {}
1219+
1220+
response = self.request_helper.request(
1221+
INVITATION_DETAIL_BY_TOKEN_PATH.format(invitation_token),
1222+
method=REQUEST_METHOD_GET,
1223+
headers=headers,
1224+
token=workos.api_key,
1225+
)
1226+
1227+
return WorkOSInvitation.construct_from_response(response).to_dict()
1228+
12081229
def list_invitations(
12091230
self,
12101231
email=None,

0 commit comments

Comments
 (0)