Skip to content

Commit 30cce46

Browse files
author
Paul Asjes
authored
Merge branch 'main' into feature/session-helpers
2 parents 3cbc6a6 + f72f68d commit 30cce46

File tree

7 files changed

+142
-4
lines changed

7 files changed

+142
-4
lines changed

tests/test_sso.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def mock_magic_link_profile(self):
3838
def mock_connection(self):
3939
return MockConnection("conn_01E4ZCR3C56J083X43JQXF3JK5").dict()
4040

41+
@pytest.fixture
42+
def mock_connection_updated(self):
43+
connection = MockConnection("conn_01FHT48Z8J8295GZNQ4ZP1J81T").dict()
44+
45+
connection["options"] = {
46+
"signing_cert": "signing_cert",
47+
}
48+
49+
return connection
50+
4151
@pytest.fixture
4252
def mock_connections(self):
4353
connection_list = [MockConnection(id=str(i)).dict() for i in range(10)]
@@ -339,6 +349,33 @@ def test_list_connections_with_connection_type(
339349
"order": "desc",
340350
}
341351

352+
def test_update_connection(
353+
self, mock_connection_updated, capture_and_mock_http_client_request
354+
):
355+
request_kwargs = capture_and_mock_http_client_request(
356+
self.http_client, mock_connection_updated, 200
357+
)
358+
359+
updated_connection = syncify(
360+
self.sso.update_connection(
361+
connection_id="conn_01EHT88Z8J8795GZNQ4ZP1J81T",
362+
saml_options_signing_key="signing_key",
363+
saml_options_signing_cert="signing_cert",
364+
)
365+
)
366+
367+
assert request_kwargs["url"].endswith(
368+
"/connections/conn_01EHT88Z8J8795GZNQ4ZP1J81T"
369+
)
370+
371+
assert request_kwargs["method"] == "put"
372+
assert request_kwargs["json"] == {
373+
"options": {"signing_key": "signing_key", "signing_cert": "signing_cert"}
374+
}
375+
assert updated_connection.id == "conn_01FHT48Z8J8295GZNQ4ZP1J81T"
376+
assert updated_connection.name == "Foo Corporation"
377+
assert updated_connection.options.signing_cert == "signing_cert"
378+
342379
def test_delete_connection(self, capture_and_mock_http_client_request):
343380
request_kwargs = capture_and_mock_http_client_request(
344381
self.http_client,

tests/test_user_management.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,26 @@ def test_authorization_url_has_expected_query_params_with_provider(self):
215215
"response_type": RESPONSE_TYPE_CODE,
216216
}
217217

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

tests/utils/fixtures/mock_connection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import datetime
2-
from workos.types.sso import ConnectionDomain, ConnectionWithDomains
2+
from workos.types.sso import (
3+
ConnectionDomain,
4+
ConnectionWithDomains,
5+
SamlConnectionOptions,
6+
)
37

48

59
class MockConnection(ConnectionWithDomains):
@@ -14,6 +18,7 @@ def __init__(self, id):
1418
state="active",
1519
created_at=now,
1620
updated_at=now,
21+
options=SamlConnectionOptions(signing_cert="signing_cert"),
1722
domains=[
1823
ConnectionDomain(
1924
id="connection_domain_abc123",

workos/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
__package_url__ = "https://github.com/workos-inc/workos-python"
1414

15-
__version__ = "5.7.0"
15+
__version__ = "5.9.0"
1616

1717
__author__ = "WorkOS"
1818

workos/sso.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
REQUEST_METHOD_POST,
1515
QueryParameters,
1616
RequestHelper,
17+
REQUEST_METHOD_PUT,
1718
)
1819
from workos.types.list_resource import (
1920
ListArgs,
@@ -167,11 +168,29 @@ def list_connections(
167168
"""
168169
...
169170

171+
def update_connection(
172+
self,
173+
*,
174+
connection_id: str,
175+
saml_options_signing_key: Optional[str] = None,
176+
saml_options_signing_cert: Optional[str] = None,
177+
) -> SyncOrAsync[ConnectionWithDomains]:
178+
"""Updates a single connection
179+
180+
Args:
181+
connection_id (str): Connection unique identifier
182+
saml_options_signing_key (str): Signing key for the connection (Optional)
183+
saml_options_signing_cert (str): Signing certificate for the connection (Optional)
184+
Returns:
185+
None
186+
"""
187+
...
188+
170189
def delete_connection(self, connection_id: str) -> SyncOrAsync[None]:
171190
"""Deletes a single Connection
172191
173192
Args:
174-
connection (str): Connection unique identifier
193+
connection_id (str): Connection unique identifier
175194
176195
Returns:
177196
None
@@ -255,6 +274,28 @@ def list_connections(
255274
**ListPage[ConnectionWithDomains](**response).model_dump(),
256275
)
257276

277+
def update_connection(
278+
self,
279+
*,
280+
connection_id: str,
281+
saml_options_signing_key: Optional[str] = None,
282+
saml_options_signing_cert: Optional[str] = None,
283+
) -> ConnectionWithDomains:
284+
json = {
285+
"options": {
286+
"signing_key": saml_options_signing_key,
287+
"signing_cert": saml_options_signing_cert,
288+
}
289+
}
290+
291+
response = self._http_client.request(
292+
f"connections/{connection_id}",
293+
method=REQUEST_METHOD_PUT,
294+
json=json,
295+
)
296+
297+
return ConnectionWithDomains.model_validate(response)
298+
258299
def delete_connection(self, connection_id: str) -> None:
259300
self._http_client.request(
260301
f"connections/{connection_id}", method=REQUEST_METHOD_DELETE
@@ -335,6 +376,28 @@ async def list_connections(
335376
**ListPage[ConnectionWithDomains](**response).model_dump(),
336377
)
337378

379+
async def update_connection(
380+
self,
381+
*,
382+
connection_id: str,
383+
saml_options_signing_key: Optional[str] = None,
384+
saml_options_signing_cert: Optional[str] = None,
385+
) -> ConnectionWithDomains:
386+
json = {
387+
"options": {
388+
"signing_key": saml_options_signing_key,
389+
"signing_cert": saml_options_signing_cert,
390+
}
391+
}
392+
393+
response = await self._http_client.request(
394+
f"connections/{connection_id}",
395+
method=REQUEST_METHOD_PUT,
396+
json=json,
397+
)
398+
399+
return ConnectionWithDomains.model_validate(response)
400+
338401
async def delete_connection(self, connection_id: str) -> None:
339402
await self._http_client.request(
340403
f"connections/{connection_id}",

workos/types/sso/connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, Sequence
1+
from typing import Literal, Sequence, Optional
22
from workos.types.sso.connection_domain import ConnectionDomain
33
from workos.types.workos_model import WorkOSModel
44
from workos.typing.literals import LiteralOrUntyped
@@ -45,6 +45,12 @@
4545
]
4646

4747

48+
class SamlConnectionOptions(WorkOSModel):
49+
"""Representation of options payload of a Connection Response."""
50+
51+
signing_cert: Optional[str]
52+
53+
4854
class Connection(WorkOSModel):
4955
object: Literal["connection"]
5056
id: str
@@ -54,6 +60,7 @@ class Connection(WorkOSModel):
5460
state: LiteralOrUntyped[ConnectionState]
5561
created_at: str
5662
updated_at: str
63+
options: Optional[SamlConnectionOptions] = None
5764

5865

5966
class ConnectionWithDomains(Connection):

workos/user_management.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def get_authorization_url(
341341
connection_id: Optional[str] = None,
342342
organization_id: Optional[str] = None,
343343
code_challenge: Optional[str] = None,
344+
prompt: Optional[str] = None,
344345
) -> str:
345346
"""Generate an OAuth 2.0 authorization URL.
346347
@@ -365,6 +366,9 @@ def get_authorization_url(
365366
state (str): An encoded string passed to WorkOS that'd be preserved through the authentication workflow, passed
366367
back as a query parameter. (Optional)
367368
code_challenge (str): Code challenge is derived from the code verifier used for the PKCE flow. (Optional)
369+
prompt (str): Used to specify whether the upstream provider should prompt the user for credentials or other
370+
consent. Valid values depend on the provider. Currently only applies to provider values of 'GoogleOAuth',
371+
'MicrosoftOAuth', or 'GitHubOAuth'. (Optional)
368372
369373
Returns:
370374
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
@@ -395,6 +399,8 @@ def get_authorization_url(
395399
if code_challenge:
396400
params["code_challenge"] = code_challenge
397401
params["code_challenge_method"] = "S256"
402+
if prompt is not None:
403+
params["prompt"] = prompt
398404

399405
return RequestHelper.build_url_with_query_params(
400406
base_url=self._client_configuration.base_url,

0 commit comments

Comments
 (0)