Skip to content

Commit af48c82

Browse files
committed
feat: Support screen_hint in user_management.get_authorization_url
1 parent dadb944 commit af48c82

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

tests/test_user_management.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,29 @@ def test_authorization_url_has_expected_query_params_with_code_challenge(self):
320320
"response_type": RESPONSE_TYPE_CODE,
321321
}
322322

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

workos/user_management.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
from workos.types.user_management.user_management_provider_type import (
4949
UserManagementProviderType,
5050
)
51+
from workos.types.user_management.screen_hint import (
52+
ScreenHintType
53+
)
5154
from workos.typing.sync_or_async import SyncOrAsync
5255
from workos.utils.http_client import AsyncHTTPClient, SyncHTTPClient
5356
from workos.utils.pagination_order import PaginationOrder
@@ -342,6 +345,7 @@ def get_authorization_url(
342345
organization_id: Optional[str] = None,
343346
code_challenge: Optional[str] = None,
344347
prompt: Optional[str] = None,
348+
screen_hint: Optional[ScreenHintType] = None,
345349
) -> str:
346350
"""Generate an OAuth 2.0 authorization URL.
347351
@@ -369,6 +373,7 @@ def get_authorization_url(
369373
prompt (str): Used to specify whether the upstream provider should prompt the user for credentials or other
370374
consent. Valid values depend on the provider. Currently only applies to provider values of 'GoogleOAuth',
371375
'MicrosoftOAuth', or 'GitHubOAuth'. (Optional)
376+
screen_hint (ScreenHintType): Specify which AuthKit screen users should land on upon redirection (Only applicable when provider is 'authkit').
372377
373378
Returns:
374379
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
@@ -401,6 +406,8 @@ def get_authorization_url(
401406
params["code_challenge_method"] = "S256"
402407
if prompt is not None:
403408
params["prompt"] = prompt
409+
if screen_hint is not None:
410+
params["screen_hint"] = screen_hint
404411

405412
return RequestHelper.build_url_with_query_params(
406413
base_url=self._client_configuration.base_url,

0 commit comments

Comments
 (0)