From 2643cb0ccec9be3f0b5b47fe9dd046f4994ee7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B4natas=20Santos?= Date: Wed, 29 Jan 2025 17:15:06 -0300 Subject: [PATCH] Add `intent_options` parameter on Portal.generate_link() method --- tests/test_portal.py | 19 ++++++++++++++++--- workos/portal.py | 7 ++++++- .../portal/portal_link_intent_options.py | 9 +++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 workos/types/portal/portal_link_intent_options.py diff --git a/tests/test_portal.py b/tests/test_portal.py index 99cf3902..64d0fbcc 100644 --- a/tests/test_portal.py +++ b/tests/test_portal.py @@ -13,13 +13,26 @@ def setup(self, sync_http_client_for_test): def mock_portal_link(self): return {"link": "https://id.workos.com/portal/launch?secret=secret"} - def test_generate_link_sso(self, mock_portal_link, mock_http_client_with_response): - mock_http_client_with_response(self.http_client, mock_portal_link, 201) + def test_generate_link_sso( + self, mock_portal_link, capture_and_mock_http_client_request + ): + request_kwargs = capture_and_mock_http_client_request( + self.http_client, mock_portal_link, 201 + ) response = self.portal.generate_link( - intent="sso", organization_id="org_01EHQMYV6MBK39QC5PZXHY59C3" + intent="sso", + organization_id="org_01EHQMYV6MBK39QC5PZXHY59C3", + intent_options={"sso": {"bookmark_slug": "my_app"}}, ) + assert request_kwargs["url"].endswith("/portal/generate_link") + assert request_kwargs["method"] == "post" + assert request_kwargs["json"] == { + "intent": "sso", + "organization": "org_01EHQMYV6MBK39QC5PZXHY59C3", + "intent_options": {"sso": {"bookmark_slug": "my_app"}}, + } assert response.link == "https://id.workos.com/portal/launch?secret=secret" def test_generate_link_domain_verification( diff --git a/workos/portal.py b/workos/portal.py index 757ef3d7..07a0ade4 100644 --- a/workos/portal.py +++ b/workos/portal.py @@ -1,6 +1,7 @@ -from typing import Optional, Protocol +from typing import Optional, Protocol, Dict, Literal, Union from workos.types.portal.portal_link import PortalLink from workos.types.portal.portal_link_intent import PortalLinkIntent +from workos.types.portal.portal_link_intent_options import IntentOptions from workos.utils.http_client import SyncHTTPClient from workos.utils.request_helper import REQUEST_METHOD_POST @@ -16,6 +17,7 @@ def generate_link( organization_id: str, return_url: Optional[str] = None, success_url: Optional[str] = None, + intent_options: Optional[IntentOptions] = None, ) -> PortalLink: """Generate a link to grant access to an organization's Admin Portal @@ -47,13 +49,16 @@ def generate_link( organization_id: str, return_url: Optional[str] = None, success_url: Optional[str] = None, + intent_options: Optional[IntentOptions] = None, ) -> PortalLink: json = { "intent": intent, "organization": organization_id, "return_url": return_url, "success_url": success_url, + "intent_options": intent_options, } + response = self._http_client.request( PORTAL_GENERATE_PATH, method=REQUEST_METHOD_POST, json=json ) diff --git a/workos/types/portal/portal_link_intent_options.py b/workos/types/portal/portal_link_intent_options.py new file mode 100644 index 00000000..6c634033 --- /dev/null +++ b/workos/types/portal/portal_link_intent_options.py @@ -0,0 +1,9 @@ +from typing import TypedDict + + +class SsoIntentOptions(TypedDict): + bookmark_slug: str + + +class IntentOptions(TypedDict): + sso: SsoIntentOptions