Skip to content

Commit

Permalink
Add intent_options_sso_bookmark_slug parameter on Portal.generate_l…
Browse files Browse the repository at this point in the history
…ink() method
  • Loading branch information
jonatascastro12 committed Jan 29, 2025
1 parent 2521bcb commit d8b5abd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 16 additions & 3 deletions tests/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions workos/portal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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.utils.http_client import SyncHTTPClient
Expand All @@ -16,6 +16,7 @@ def generate_link(
organization_id: str,
return_url: Optional[str] = None,
success_url: Optional[str] = None,
intent_options_sso_bookmark_slug: Optional[str] = None,
) -> PortalLink:
"""Generate a link to grant access to an organization's Admin Portal
Expand Down Expand Up @@ -47,13 +48,22 @@ def generate_link(
organization_id: str,
return_url: Optional[str] = None,
success_url: Optional[str] = None,
intent_options_sso_bookmark_slug: Optional[str] = None,
) -> PortalLink:
json = {
json: dict[str, Union[str, None, dict[str, dict[str, str]]]] = {
"intent": intent,
"organization": organization_id,
"return_url": return_url,
"success_url": success_url,
}

if intent_options_sso_bookmark_slug:
json["intent_options"] = {
"sso": {
"bookmark_slug": intent_options_sso_bookmark_slug,
}
}

response = self._http_client.request(
PORTAL_GENERATE_PATH, method=REQUEST_METHOD_POST, json=json
)
Expand Down

0 comments on commit d8b5abd

Please sign in to comment.