Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add intent_options parameter on Portal.generate_link() method #406

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
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
7 changes: 6 additions & 1 deletion workos/portal.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
)
Expand Down
9 changes: 9 additions & 0 deletions workos/types/portal/portal_link_intent_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import TypedDict


class SsoIntentOptions(TypedDict):
bookmark_slug: str


class IntentOptions(TypedDict):
sso: SsoIntentOptions