Skip to content

Commit 34f093d

Browse files
authored
Add GET /connections (#51)
1 parent ea72f62 commit 34f093d

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

tests/test_sso.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from requests import Response
23
from six.moves.urllib.parse import parse_qsl, urlparse
34

45
import pytest
@@ -60,6 +61,35 @@ def mock_connection(self):
6061
],
6162
}
6263

64+
@pytest.fixture
65+
def mock_connections(self):
66+
return {
67+
"data": [
68+
{
69+
"object": "connection",
70+
"id": "conn_id",
71+
"status": "linked",
72+
"name": "Google OAuth 2.0",
73+
"connection_type": "GoogleOAuth",
74+
"oauth_uid": "oauth-uid.apps.googleusercontent.com",
75+
"oauth_secret": "oauth-secret",
76+
"oauth_redirect_uri": "https://auth.workos.com/sso/oauth/google/chicken/callback",
77+
"saml_entity_id": None,
78+
"saml_idp_url": None,
79+
"saml_relying_party_trust_cert": None,
80+
"saml_x509_certs": None,
81+
"domains": [
82+
{
83+
"object": "connection_domain",
84+
"id": "domain_id",
85+
"domain": "terrace-house.com",
86+
},
87+
],
88+
}
89+
],
90+
"listMetadata": {"before": None, "after": None},
91+
}
92+
6393
def test_authorization_url_throws_value_error_with_missing_domain_and_provider(
6494
self,
6595
):
@@ -177,3 +207,12 @@ def test_create_connection(self, mock_request_method, mock_connection):
177207

178208
connection = self.sso.create_connection("draft_conn_id")
179209
assert connection == response_dict
210+
211+
def test_list_connections(self, mock_connections, mock_request_method):
212+
mock_response = Response()
213+
mock_response.status_code = 200
214+
mock_response.response_dict = mock_connections
215+
mock_request_method("get", mock_response, 200)
216+
response = self.sso.list_connections()
217+
assert response.status_code == 200
218+
assert response.response_dict == mock_connections

workos/sso.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from workos.exceptions import ConfigurationException
88
from workos.resources.sso import WorkOSProfile
99
from workos.utils.connection_types import ConnectionType
10-
from workos.utils.request import RequestHelper, RESPONSE_TYPE_CODE, REQUEST_METHOD_POST
10+
from workos.utils.request import (
11+
RequestHelper,
12+
RESPONSE_TYPE_CODE,
13+
REQUEST_METHOD_GET,
14+
REQUEST_METHOD_POST,
15+
)
1116
from workos.utils.validation import SSO_MODULE, validate_settings
1217

1318
AUTHORIZATION_PATH = "sso/authorize"
@@ -17,6 +22,8 @@
1722

1823
OAUTH_GRANT_TYPE = "authorization_code"
1924

25+
RESPONSE_LIMIT = 10
26+
2027

2128
class SSO(object):
2229
"""Offers methods to assist in authenticating through the WorkOS SSO service."""
@@ -157,3 +164,37 @@ def create_connection(self, source):
157164
params=params,
158165
token=workos.api_key,
159166
)
167+
168+
def list_connections(
169+
self,
170+
connection_type=None,
171+
domain=None,
172+
limit=RESPONSE_LIMIT,
173+
before=None,
174+
after=None,
175+
):
176+
"""Gets details for existing Connections.
177+
178+
Args:
179+
connection_type (ConnectionType): Authentication service provider descriptor. (Optional)
180+
domain (str): Domain of a Connection. (Optional)
181+
limit (int): Maximum number of records to return. (Optional)
182+
before (str): Pagination cursor to receive records before a provided Connection ID. (Optional)
183+
after (str): Pagination cursor to receive records after a provided Connection ID. (Optional)
184+
185+
Returns:
186+
dict: Connections response from WorkOS.
187+
"""
188+
params = {
189+
"connetion_type": connection_type,
190+
"domain": domain,
191+
"limit": limit,
192+
"before": before,
193+
"after": after,
194+
}
195+
return self.request_helper.request(
196+
"connections",
197+
method=REQUEST_METHOD_GET,
198+
params=params,
199+
token=workos.api_key,
200+
)

0 commit comments

Comments
 (0)