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
15 changes: 15 additions & 0 deletions tests/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class TestPortal(object):
def setup(self, set_api_key):
self.portal = Portal()

@pytest.fixture
def mock_portal_link(self):
return {"link": "https://id.workos.com/portal/launch?secret=secret"}

@pytest.fixture
def mock_organization(self):
return {
Expand Down Expand Up @@ -73,6 +77,17 @@ def test_create_organization(self, mock_organization, mock_request_method):
assert subject["id"] == "org_01EHT88Z8J8795GZNQ4ZP1J81T"
assert subject["name"] == "Test Organization"

def test_generate_link(self, mock_portal_link, mock_request_method):
mock_response = Response()
mock_response.status_code = 201
mock_response.response_dict = mock_portal_link
mock_request_method("post", mock_response, 201)

result = self.portal.generate_link("sso", "org_01EHQMYV6MBK39QC5PZXHY59C3")
subject = result.response_dict

assert subject["link"] == "https://id.workos.com/portal/launch?secret=secret"

def test_list_organizations(self, mock_organizations, mock_request_method):
mock_response = Response()
mock_response.status_code = 200
Expand Down
26 changes: 26 additions & 0 deletions workos/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from workos.utils.validation import PORTAL_MODULE, validate_settings

ORGANIZATIONS_PATH = "organizations"
PORTAL_GENERATE_PATH = "portal/generate_link"
RESPONSE_LIMIT = 10


Expand Down Expand Up @@ -35,6 +36,31 @@ def create_organization(self, organization):
token=workos.api_key,
)

def generate_link(self, intent, organization, return_url=None):
"""Generate a link to grant access to an organization's Admin Portal

Args:
intent (str): The access scope for the generated Admin Portal link. Valid values are: ["sso"]
organization (string): The ID of the organization the Admin Portal link will be generated for

Kwargs:
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move return_url into a Kwargs section?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a discussion for some other time but... it's called return_url but we're using the default reDirect_uri if one is not supplied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had the same question as I was writing this. @maxchehab?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are deciding to keep this as is. See slack convo.


Returns:
str: URL to redirect a User to to access an Admin Portal session
"""
params = {
"intent": intent,
"organization": organization,
"return_url": return_url,
}
return self.request_helper.request(
PORTAL_GENERATE_PATH,
method=REQUEST_METHOD_POST,
params=params,
token=workos.api_key,
)

def list_organizations(
self, domains=None, limit=RESPONSE_LIMIT, before=None, after=None
):
Expand Down