Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,37 @@ def test_authenticate_impersonator_with_code(
"grant_type": "authorization_code",
}

def test_authenticate_with_code_with_invitation_token(
self,
capture_and_mock_http_client_request,
mock_auth_response,
base_authentication_params,
):
params = {
"code": "test_code",
"code_verifier": "test_code_verifier",
"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",
"ip_address": "192.0.0.1",
"invitation_token": "invitation_token_12345",
}
request_kwargs = capture_and_mock_http_client_request(
self.http_client, mock_auth_response, 200
)

response = syncify(self.user_management.authenticate_with_code(**params))

assert request_kwargs["url"].endswith("user_management/authenticate")
assert request_kwargs["method"] == "post"
assert response.user.id == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0"
assert response.organization_id == "org_12345"
assert response.access_token == "access_token_12345"
assert response.refresh_token == "refresh_token_12345"
assert request_kwargs["json"] == {
**params,
**base_authentication_params,
"grant_type": "authorization_code",
}

def test_authenticate_with_magic_auth(
self,
capture_and_mock_http_client_request,
Expand Down
1 change: 1 addition & 0 deletions workos/types/user_management/authenticate_with_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AuthenticateWithCodeParameters(AuthenticateWithBaseParameters):
code_verifier: Union[str, None]
grant_type: Literal["authorization_code"]
session: Union[SessionConfig, None]
invitation_token: Union[str, None]


class AuthenticateWithMagicAuthParameters(AuthenticateWithBaseParameters):
Expand Down
6 changes: 6 additions & 0 deletions workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ def authenticate_with_code(
code_verifier: Optional[str] = None,
ip_address: Optional[str] = None,
user_agent: Optional[str] = None,
invitation_token: Optional[str] = None,
) -> SyncOrAsync[AuthenticationResponse]:
"""Authenticates an OAuth user or a user that is logging in through SSO.

Expand All @@ -498,6 +499,7 @@ def authenticate_with_code(
url as part of the PKCE flow. This parameter is required when the client secret is not present. (Optional)
ip_address (str): The IP address of the request from the user who is attempting to authenticate. (Optional)
user_agent (str): The user agent of the request from the user who is attempting to authenticate. (Optional)
invitation_token (str): The token of an Invitation, if required. (Optional)

Returns:
AuthenticationResponse: Authentication response from WorkOS.
Expand Down Expand Up @@ -1166,6 +1168,7 @@ def authenticate_with_code(
code_verifier: Optional[str] = None,
ip_address: Optional[str] = None,
user_agent: Optional[str] = None,
invitation_token: Optional[str] = None,
) -> AuthKitAuthenticationResponse:
if (
session is not None
Expand All @@ -1181,6 +1184,7 @@ def authenticate_with_code(
"user_agent": user_agent,
"code_verifier": code_verifier,
"session": session,
"invitation_token": invitation_token,
}

return self._authenticate_with(
Expand Down Expand Up @@ -1807,6 +1811,7 @@ async def authenticate_with_code(
code_verifier: Optional[str] = None,
ip_address: Optional[str] = None,
user_agent: Optional[str] = None,
invitation_token: Optional[str] = None,
) -> AuthKitAuthenticationResponse:
if (
session is not None
Expand All @@ -1822,6 +1827,7 @@ async def authenticate_with_code(
"user_agent": user_agent,
"code_verifier": code_verifier,
"session": session,
"invitation_token": invitation_token,
}

return await self._authenticate_with(
Expand Down