Skip to content

Commit 079586f

Browse files
Add prompt option to creating authorization urls (#383)
* Add prompt option to creating authorization urls * Add test * Update doc string to be more specific about usage --------- Co-authored-by: Michael Hadley <[email protected]>
1 parent f05a0ec commit 079586f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/test_user_management.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ def test_authorization_url_has_expected_query_params_with_provider(self):
212212
"response_type": RESPONSE_TYPE_CODE,
213213
}
214214

215+
def test_authorization_url_has_expected_query_params_with_prompt(self):
216+
provider = "GoogleOAuth"
217+
redirect_uri = "https://localhost/auth/callback"
218+
prompt = "consent"
219+
authorization_url = self.user_management.get_authorization_url(
220+
provider=provider,
221+
redirect_uri=redirect_uri,
222+
prompt=prompt,
223+
)
224+
225+
parsed_url = urlparse(authorization_url)
226+
assert parsed_url.path == "/user_management/authorize"
227+
assert dict(parse_qsl(str(parsed_url.query))) == {
228+
"client_id": self.http_client.client_id,
229+
"redirect_uri": redirect_uri,
230+
"response_type": RESPONSE_TYPE_CODE,
231+
"provider": provider,
232+
"prompt": prompt,
233+
}
234+
215235
def test_authorization_url_has_expected_query_params_with_domain_hint(self):
216236
connection_id = "connection_123"
217237
redirect_uri = "https://localhost/auth/callback"

workos/user_management.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def get_authorization_url(
325325
connection_id: Optional[str] = None,
326326
organization_id: Optional[str] = None,
327327
code_challenge: Optional[str] = None,
328+
prompt: Optional[str] = None,
328329
) -> str:
329330
"""Generate an OAuth 2.0 authorization URL.
330331
@@ -349,6 +350,9 @@ def get_authorization_url(
349350
state (str): An encoded string passed to WorkOS that'd be preserved through the authentication workflow, passed
350351
back as a query parameter. (Optional)
351352
code_challenge (str): Code challenge is derived from the code verifier used for the PKCE flow. (Optional)
353+
prompt (str): Used to specify whether the upstream provider should prompt the user for credentials or other
354+
consent. Valid values depend on the provider. Currently only applies to provider values of 'GoogleOAuth',
355+
'MicrosoftOAuth', or 'GitHubOAuth'. (Optional)
352356
353357
Returns:
354358
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
@@ -379,6 +383,8 @@ def get_authorization_url(
379383
if code_challenge:
380384
params["code_challenge"] = code_challenge
381385
params["code_challenge_method"] = "S256"
386+
if prompt is not None:
387+
params["prompt"] = prompt
382388

383389
return RequestHelper.build_url_with_query_params(
384390
base_url=self._client_configuration.base_url,

0 commit comments

Comments
 (0)