Skip to content

Commit 4b3c7bf

Browse files
authored
feat: Support screen_hint in user_management.get_authorization_url (#396)
* feat: Support screen_hint in user_management.get_authorization_url * Format * Format * Format * Format
1 parent dadb944 commit 4b3c7bf

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

tests/test_user_management.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ def mock_invitations_multiple_pages(self):
150150
class TestUserManagementBase(UserManagementFixtures):
151151
@pytest.fixture(autouse=True)
152152
def setup(self, sync_client_configuration_and_http_client_for_test):
153-
client_configuration, http_client = (
154-
sync_client_configuration_and_http_client_for_test
155-
)
153+
(
154+
client_configuration,
155+
http_client,
156+
) = sync_client_configuration_and_http_client_for_test
156157
self.http_client = http_client
157158
self.user_management = UserManagement(
158159
http_client=self.http_client, client_configuration=client_configuration
@@ -320,6 +321,29 @@ def test_authorization_url_has_expected_query_params_with_code_challenge(self):
320321
"response_type": RESPONSE_TYPE_CODE,
321322
}
322323

324+
def test_authorization_url_has_expected_query_params_with_screen_hint(self):
325+
connection_id = "connection_123"
326+
redirect_uri = "https://localhost/auth/callback"
327+
screen_hint = "sign-up"
328+
329+
authorization_url = self.user_management.get_authorization_url(
330+
connection_id=connection_id,
331+
screen_hint=screen_hint,
332+
redirect_uri=redirect_uri,
333+
provider="authkit",
334+
)
335+
336+
parsed_url = urlparse(authorization_url)
337+
assert parsed_url.path == "/user_management/authorize"
338+
assert dict(parse_qsl(str(parsed_url.query))) == {
339+
"screen_hint": screen_hint,
340+
"client_id": self.http_client.client_id,
341+
"redirect_uri": redirect_uri,
342+
"connection_id": connection_id,
343+
"response_type": RESPONSE_TYPE_CODE,
344+
"provider": "authkit",
345+
}
346+
323347
def test_get_jwks_url(self):
324348
expected = "%ssso/jwks/%s" % (
325349
self.http_client.base_url,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from typing import Literal
2+
3+
ScreenHintType = Literal["sign-up", "sign-in"]

workos/user_management.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
UsersListFilters,
4545
)
4646
from workos.types.user_management.password_hash_type import PasswordHashType
47+
from workos.types.user_management.screen_hint import ScreenHintType
4748
from workos.types.user_management.session import SessionConfig
4849
from workos.types.user_management.user_management_provider_type import (
4950
UserManagementProviderType,
@@ -342,6 +343,7 @@ def get_authorization_url(
342343
organization_id: Optional[str] = None,
343344
code_challenge: Optional[str] = None,
344345
prompt: Optional[str] = None,
346+
screen_hint: Optional[ScreenHintType] = None,
345347
) -> str:
346348
"""Generate an OAuth 2.0 authorization URL.
347349
@@ -369,6 +371,7 @@ def get_authorization_url(
369371
prompt (str): Used to specify whether the upstream provider should prompt the user for credentials or other
370372
consent. Valid values depend on the provider. Currently only applies to provider values of 'GoogleOAuth',
371373
'MicrosoftOAuth', or 'GitHubOAuth'. (Optional)
374+
screen_hint (ScreenHintType): Specify which AuthKit screen users should land on upon redirection (Only applicable when provider is 'authkit').
372375
373376
Returns:
374377
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
@@ -385,6 +388,7 @@ def get_authorization_url(
385388
)
386389

387390
if connection_id is not None:
391+
388392
params["connection_id"] = connection_id
389393
if organization_id is not None:
390394
params["organization_id"] = organization_id
@@ -401,6 +405,8 @@ def get_authorization_url(
401405
params["code_challenge_method"] = "S256"
402406
if prompt is not None:
403407
params["prompt"] = prompt
408+
if screen_hint is not None:
409+
params["screen_hint"] = screen_hint
404410

405411
return RequestHelper.build_url_with_query_params(
406412
base_url=self._client_configuration.base_url,

0 commit comments

Comments
 (0)