Skip to content

Commit decd7b1

Browse files
authored
add authenticate with invite_token to authenticate_with_code (#481)
1 parent fcce7bc commit decd7b1

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

tests/test_user_management.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,37 @@ def test_authenticate_impersonator_with_code(
718718
"grant_type": "authorization_code",
719719
}
720720

721+
def test_authenticate_with_code_with_invitation_token(
722+
self,
723+
capture_and_mock_http_client_request,
724+
mock_auth_response,
725+
base_authentication_params,
726+
):
727+
params = {
728+
"code": "test_code",
729+
"code_verifier": "test_code_verifier",
730+
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
731+
"ip_address": "192.0.0.1",
732+
"invitation_token": "invitation_token_12345",
733+
}
734+
request_kwargs = capture_and_mock_http_client_request(
735+
self.http_client, mock_auth_response, 200
736+
)
737+
738+
response = syncify(self.user_management.authenticate_with_code(**params))
739+
740+
assert request_kwargs["url"].endswith("user_management/authenticate")
741+
assert request_kwargs["method"] == "post"
742+
assert response.user.id == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
743+
assert response.organization_id == "org_12345"
744+
assert response.access_token == "access_token_12345"
745+
assert response.refresh_token == "refresh_token_12345"
746+
assert request_kwargs["json"] == {
747+
**params,
748+
**base_authentication_params,
749+
"grant_type": "authorization_code",
750+
}
751+
721752
def test_authenticate_with_magic_auth(
722753
self,
723754
capture_and_mock_http_client_request,

workos/types/user_management/authenticate_with_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AuthenticateWithCodeParameters(AuthenticateWithBaseParameters):
1919
code_verifier: Union[str, None]
2020
grant_type: Literal["authorization_code"]
2121
session: Union[SessionConfig, None]
22+
invitation_token: Union[str, None]
2223

2324

2425
class AuthenticateWithMagicAuthParameters(AuthenticateWithBaseParameters):

workos/user_management.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ def authenticate_with_code(
488488
code_verifier: Optional[str] = None,
489489
ip_address: Optional[str] = None,
490490
user_agent: Optional[str] = None,
491+
invitation_token: Optional[str] = None,
491492
) -> SyncOrAsync[AuthenticationResponse]:
492493
"""Authenticates an OAuth user or a user that is logging in through SSO.
493494
@@ -498,6 +499,7 @@ def authenticate_with_code(
498499
url as part of the PKCE flow. This parameter is required when the client secret is not present. (Optional)
499500
ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
500501
user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
502+
invitation_token (str): The token of an Invitation, if required. (Optional)
501503
502504
Returns:
503505
AuthenticationResponse: Authentication response from WorkOS.
@@ -1166,6 +1168,7 @@ def authenticate_with_code(
11661168
code_verifier: Optional[str] = None,
11671169
ip_address: Optional[str] = None,
11681170
user_agent: Optional[str] = None,
1171+
invitation_token: Optional[str] = None,
11691172
) -> AuthKitAuthenticationResponse:
11701173
if (
11711174
session is not None
@@ -1181,6 +1184,7 @@ def authenticate_with_code(
11811184
"user_agent": user_agent,
11821185
"code_verifier": code_verifier,
11831186
"session": session,
1187+
"invitation_token": invitation_token,
11841188
}
11851189

11861190
return self._authenticate_with(
@@ -1807,6 +1811,7 @@ async def authenticate_with_code(
18071811
code_verifier: Optional[str] = None,
18081812
ip_address: Optional[str] = None,
18091813
user_agent: Optional[str] = None,
1814+
invitation_token: Optional[str] = None,
18101815
) -> AuthKitAuthenticationResponse:
18111816
if (
18121817
session is not None
@@ -1822,6 +1827,7 @@ async def authenticate_with_code(
18221827
"user_agent": user_agent,
18231828
"code_verifier": code_verifier,
18241829
"session": session,
1830+
"invitation_token": invitation_token,
18251831
}
18261832

18271833
return await self._authenticate_with(

0 commit comments

Comments
 (0)