Skip to content

Commit df63afa

Browse files
author
Rohan Jadvani
authored
Add create_connection method in SSO package (#26)
1 parent 11deee3 commit df63afa

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

tests/test_sso.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ def mock_profile(self):
3232
"idp_id": "00u1klkowm8EGah2H357",
3333
}
3434

35+
@pytest.fixture
36+
def mock_connection(self):
37+
return {
38+
"object": "connection",
39+
"id": "conn_id",
40+
"status": "linked",
41+
"name": "Google OAuth 2.0",
42+
"connection_type": "GoogleOAuth",
43+
"oauth_uid": "oauth-uid.apps.googleusercontent.com",
44+
"oauth_secret": "oauth-secret",
45+
"oauth_redirect_uri": "https://auth.workos.com/sso/oauth/google/chicken/callback",
46+
"saml_entity_id": None,
47+
"saml_idp_url": None,
48+
"saml_relying_party_trust_cert": None,
49+
"saml_x509_certs": None,
50+
"domains": [
51+
{
52+
"object": "connection_domain",
53+
"id": "domain_id",
54+
"domain": "terrace-house.com",
55+
},
56+
],
57+
}
58+
3559
def test_authorization_url_throws_value_error_with_missing_domain_and_provider(
3660
self,
3761
):
@@ -120,3 +144,26 @@ def test_get_profile_returns_expected_workosprofile_object(
120144
profile = self.sso.get_profile(123)
121145

122146
assert profile.to_dict() == mock_profile
147+
148+
def test_create_connection(self, mock_request_method, mock_connection):
149+
response_dict = {
150+
"object": "connection",
151+
"id": mock_connection["id"],
152+
"name": mock_connection["name"],
153+
"status": mock_connection["status"],
154+
"connection_type": mock_connection["connection_type"],
155+
"oauth_uid": mock_connection["oauth_uid"],
156+
"oauth_secret": mock_connection["oauth_secret"],
157+
"oauth_redirect_uri": mock_connection["oauth_redirect_uri"],
158+
"saml_entity_id": mock_connection["saml_entity_id"],
159+
"saml_idp_url": mock_connection["saml_idp_url"],
160+
"saml_relying_party_trust_cert": mock_connection[
161+
"saml_relying_party_trust_cert"
162+
],
163+
"saml_x509_certs": mock_connection["saml_x509_certs"],
164+
"domains": mock_connection["domains"],
165+
}
166+
mock_request_method("post", mock_connection, 201)
167+
168+
connection = self.sso.create_connection("draft_conn_id")
169+
assert connection == response_dict

workos/sso.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from requests import Request
4+
from warnings import warn
45

56
import workos
67
from workos.exceptions import ConfigurationException
@@ -10,6 +11,7 @@
1011
from workos.utils.validation import SSO_MODULE, validate_settings
1112

1213
AUTHORIZATION_PATH = "sso/authorize"
14+
CREATE_CONNECTION_PATH = "connections"
1315
PROMOTE_DRAFT_CONNECTION_PATH = "draft_connections/%s/activate"
1416
TOKEN_PATH = "sso/token"
1517

@@ -113,10 +115,31 @@ def promote_draft_connection(self, token):
113115
Returns:
114116
bool: True if a Draft Connection has been successfully promoted
115117
"""
118+
warn(
119+
"'promote_draft_connection' is deprecated. Use 'create_connection' instead.",
120+
DeprecationWarning,
121+
)
116122
self.request_helper.request(
117123
PROMOTE_DRAFT_CONNECTION_PATH % token,
118124
method=REQUEST_METHOD_POST,
119125
token=workos.api_key,
120126
)
121127

122128
return True
129+
130+
def create_connection(self, source):
131+
"""Activates a Draft Connection created through the WorkOS.js widget.
132+
133+
Args:
134+
source (str): Draft Connection identifier.
135+
136+
Returns:
137+
dict: Created Connection response from WorkOS.
138+
"""
139+
params = {"source": source}
140+
return self.request_helper.request(
141+
CREATE_CONNECTION_PATH,
142+
method=REQUEST_METHOD_POST,
143+
params=params,
144+
token=workos.api_key,
145+
)

0 commit comments

Comments
 (0)