Skip to content

Commit 1eac351

Browse files
authored
Add generate_link function to Portal module (#39)
* Adds an SDK method to generate an Admin Portal link.
1 parent af49b54 commit 1eac351

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/test_portal.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ class TestPortal(object):
1212
def setup(self, set_api_key):
1313
self.portal = Portal()
1414

15+
@pytest.fixture
16+
def mock_portal_link(self):
17+
return {"link": "https://id.workos.com/portal/launch?secret=secret"}
18+
1519
@pytest.fixture
1620
def mock_organization(self):
1721
return {
@@ -73,6 +77,17 @@ def test_create_organization(self, mock_organization, mock_request_method):
7377
assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T"
7478
assert subject["name"] == "Test Organization"
7579

80+
def test_generate_link(self, mock_portal_link, mock_request_method):
81+
mock_response = Response()
82+
mock_response.status_code = 201
83+
mock_response.response_dict = mock_portal_link
84+
mock_request_method("post", mock_response, 201)
85+
86+
result = self.portal.generate_link("sso", "org_01EHQMYV6MBK39QC5PZXHY59C3")
87+
subject = result.response_dict
88+
89+
assert subject["link"] == "https://id.workos.com/portal/launch?secret=secret"
90+
7691
def test_list_organizations(self, mock_organizations, mock_request_method):
7792
mock_response = Response()
7893
mock_response.status_code = 200

workos/portal.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from workos.utils.validation import PORTAL_MODULE, validate_settings
44

55
ORGANIZATIONS_PATH = "organizations"
6+
PORTAL_GENERATE_PATH = "portal/generate_link"
67
RESPONSE_LIMIT = 10
78

89

@@ -35,6 +36,31 @@ def create_organization(self, organization):
3536
token=workos.api_key,
3637
)
3738

39+
def generate_link(self, intent, organization, return_url=None):
40+
"""Generate a link to grant access to an organization's Admin Portal
41+
42+
Args:
43+
intent (str): The access scope for the generated Admin Portal link. Valid values are: ["sso"]
44+
organization (string): The ID of the organization the Admin Portal link will be generated for
45+
46+
Kwargs:
47+
return_url (str): The URL that the end user will be redirected to upon exiting the generated Admin Portal. If none is provided, the default redirect link set in your WorkOS Dashboard will be used. (Optional)
48+
49+
Returns:
50+
str: URL to redirect a User to to access an Admin Portal session
51+
"""
52+
params = {
53+
"intent": intent,
54+
"organization": organization,
55+
"return_url": return_url,
56+
}
57+
return self.request_helper.request(
58+
PORTAL_GENERATE_PATH,
59+
method=REQUEST_METHOD_POST,
60+
params=params,
61+
token=workos.api_key,
62+
)
63+
3864
def list_organizations(
3965
self, domains=None, limit=RESPONSE_LIMIT, before=None, after=None
4066
):

0 commit comments

Comments
 (0)