Skip to content

Commit

Permalink
Add prompt option to creating authorization urls (#383)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
salbito-workos and mthadley authored Nov 22, 2024
1 parent f05a0ec commit 079586f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ def test_authorization_url_has_expected_query_params_with_provider(self):
"response_type": RESPONSE_TYPE_CODE,
}

def test_authorization_url_has_expected_query_params_with_prompt(self):
provider = "GoogleOAuth"
redirect_uri = "https://localhost/auth/callback"
prompt = "consent"
authorization_url = self.user_management.get_authorization_url(
provider=provider,
redirect_uri=redirect_uri,
prompt=prompt,
)

parsed_url = urlparse(authorization_url)
assert parsed_url.path == "/user_management/authorize"
assert dict(parse_qsl(str(parsed_url.query))) == {
"client_id": self.http_client.client_id,
"redirect_uri": redirect_uri,
"response_type": RESPONSE_TYPE_CODE,
"provider": provider,
"prompt": prompt,
}

def test_authorization_url_has_expected_query_params_with_domain_hint(self):
connection_id = "connection_123"
redirect_uri = "https://localhost/auth/callback"
Expand Down
6 changes: 6 additions & 0 deletions workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def get_authorization_url(
connection_id: Optional[str] = None,
organization_id: Optional[str] = None,
code_challenge: Optional[str] = None,
prompt: Optional[str] = None,
) -> str:
"""Generate an OAuth 2.0 authorization URL.
Expand All @@ -349,6 +350,9 @@ def get_authorization_url(
state (str): An encoded string passed to WorkOS that'd be preserved through the authentication workflow, passed
back as a query parameter. (Optional)
code_challenge (str): Code challenge is derived from the code verifier used for the PKCE flow. (Optional)
prompt (str): Used to specify whether the upstream provider should prompt the user for credentials or other
consent. Valid values depend on the provider. Currently only applies to provider values of 'GoogleOAuth',
'MicrosoftOAuth', or 'GitHubOAuth'. (Optional)
Returns:
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
Expand Down Expand Up @@ -379,6 +383,8 @@ def get_authorization_url(
if code_challenge:
params["code_challenge"] = code_challenge
params["code_challenge_method"] = "S256"
if prompt is not None:
params["prompt"] = prompt

return RequestHelper.build_url_with_query_params(
base_url=self._client_configuration.base_url,
Expand Down

0 comments on commit 079586f

Please sign in to comment.