Skip to content

Commit d5aaa07

Browse files
committed
feat: Support screen_hint in user_management.get_authorization_url
1 parent 6ea991c commit d5aaa07

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tests/test_user_management.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from tests.utils.fixtures.mock_user import MockUser
1414
from workos.user_management import UserManagement
1515
from workos.utils.um_provider_types import UserManagementProviderType
16+
from workos.utils.um_screen_hint_types import UserManagementScreenHintType
1617
from workos.utils.request import RESPONSE_TYPE_CODE
1718

1819

@@ -508,6 +509,49 @@ def test_authorization_url_throws_value_error_with_incorrect_provider_type(
508509
redirect_uri=redirect_uri,
509510
)
510511

512+
@pytest.mark.parametrize(
513+
"invalid_screen_hint",
514+
[
515+
123,
516+
UserManagementScreenHintType,
517+
True,
518+
False,
519+
{"screen_hint": "Something"},
520+
["Something"],
521+
],
522+
)
523+
def test_authorization_url_throws_value_error_with_incorrect_screen_hint_type(
524+
self, invalid_screen_hint
525+
):
526+
with pytest.raises(
527+
ValueError, match="'screen_hint' must be of type UserManagementScreenHintType"
528+
):
529+
redirect_uri = "https://localhost/auth/callback"
530+
self.user_management.get_authorization_url(
531+
screen_hint=invalid_screen_hint,
532+
redirect_uri=redirect_uri,
533+
provider=UserManagementProviderType.AuthKit
534+
)
535+
536+
def test_authorization_url_has_expected_query_params_with_screen_hint(self):
537+
screen_hint = UserManagementScreenHintType.SignUp
538+
redirect_uri = "https://localhost/auth/callback"
539+
authorization_url = self.user_management.get_authorization_url(
540+
screen_hint=screen_hint,
541+
redirect_uri=redirect_uri,
542+
provider=UserManagementProviderType.AuthKit
543+
)
544+
545+
parsed_url = urlparse(authorization_url)
546+
547+
assert dict(parse_qsl(parsed_url.query)) == {
548+
"screen_hint": screen_hint.value,
549+
"client_id": workos.client_id,
550+
"redirect_uri": redirect_uri,
551+
"response_type": RESPONSE_TYPE_CODE,
552+
"provider": UserManagementProviderType.AuthKit.value
553+
}
554+
511555
def test_authorization_url_has_expected_query_params_with_connection_id(self):
512556
connection_id = "connection_123"
513557
redirect_uri = "https://localhost/auth/callback"

workos/user_management.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717
from workos.utils.pagination_order import Order
1818
from workos.utils.um_provider_types import UserManagementProviderType
19+
from workos.utils.um_screen_hint_types import UserManagementScreenHintType
1920
from workos.utils.request import (
2021
RequestHelper,
2122
RESPONSE_TYPE_CODE,
@@ -424,6 +425,7 @@ def get_authorization_url(
424425
login_hint=None,
425426
state=None,
426427
code_challenge=None,
428+
screen_hint=None
427429
):
428430
"""Generate an OAuth 2.0 authorization URL.
429431
@@ -446,6 +448,7 @@ def get_authorization_url(
446448
state (str) - An encoded string passed to WorkOS that'd be preserved through the authentication workflow, passed
447449
back as a query parameter. (Optional)
448450
code_challenge (str) - Code challenge is derived from the code verifier used for the PKCE flow. (Optional)
451+
screen_hint (UserManagementScreenHintType) - Specify which AuthKit screen users should land on upon redirection (Only applicable when provider is 'authkit').
449452
450453
Returns:
451454
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
@@ -481,6 +484,13 @@ def get_authorization_url(
481484
if code_challenge:
482485
params["code_challenge"] = code_challenge
483486
params["code_challenge_method"] = "S256"
487+
if screen_hint is not None:
488+
if not isinstance(screen_hint, UserManagementScreenHintType):
489+
raise ValueError(
490+
"'screen_hint' must be of type UserManagementScreenHintType"
491+
)
492+
493+
params["screen_hint"] = screen_hint.value
484494

485495
prepared_request = Request(
486496
"GET",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from enum import Enum
2+
3+
4+
class UserManagementScreenHintType(Enum):
5+
SignUp = "sign-up"
6+
SignIn = "sign-in"

0 commit comments

Comments
 (0)