Skip to content

Commit ea72f62

Browse files
authored
Feature/ch4527-32/sdk-updates-for-dashboard2 (#50)
* added clientID to sso.py params * use clientID in __init__.py, updated values in sso.py, tests, and README for sdk * added environment_id to object field of event_action.py * removed project_id from object field in event_action.py * update test fixtures to use environment_id instead of project_id * removed project_id environment variable from __init__.py * improving client_id test fixtures after merging feature/ch4528/python-use-client-id-in-init-py * fixing tests * fixed formatting errors with black * re-ran black with black==19.10b0 instead of latest version to match with semaphore * requested changes made * requested changes to sso.py * requested changes made, falling back to project_id with deprecation
1 parent 1f832c1 commit ea72f62

File tree

10 files changed

+44
-23
lines changed

10 files changed

+44
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ python setup.py install
1616

1717
## Getting Started
1818

19-
The package will need to be configured with your [api key](https://dashboard.workos.com/api-keys) at a minimum and [project id](https://dashboard.workos.com/sso/configuration) if you plan on utilizing SSO:
19+
The package will need to be configured with your [api key](https://dashboard.workos.com/api-keys) at a minimum and [client id](https://dashboard.workos.com/sso/configuration) if you plan on utilizing SSO:
2020
```python
2121
import workos
2222

2323
workos.api_key = sk_abdsomecharactersm284
24-
workos.project_id = project_b27needthisforssotemxo
24+
workos.client_id = client_b27needthisforssotemxo
2525
```
2626

2727
For your convenience, a client is available as an entry point for accessing the WorkOS feature set:

tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ def set_api_key(monkeypatch):
1919
monkeypatch.setattr(workos, "api_key", "sk_abdsomecharactersm284")
2020

2121

22+
@pytest.fixture
23+
def set_client_id(monkeypatch):
24+
monkeypatch.setattr(workos, "client_id", "client_b27needthisforssotemxo")
25+
26+
2227
@pytest.fixture
2328
def set_project_id(monkeypatch):
2429
monkeypatch.setattr(workos, "project_id", "project_b27needthisforssotemxo")
2530

2631

32+
@pytest.fixture
33+
def set_api_key_and_client_id(set_api_key, set_client_id):
34+
pass
35+
36+
2737
@pytest.fixture
2838
def set_api_key_and_project_id(set_api_key, set_project_id):
2939
pass

tests/test_audit_trail.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class TestAuditTrail(object):
1212
@pytest.fixture(autouse=True)
13-
def setup(self, set_api_key_and_project_id):
13+
def setup(self, set_api_key):
1414
self.audit_trail = AuditTrail()
1515

1616
def test_create_audit_trail_event_succeeds(self, mock_request_method):
@@ -60,7 +60,7 @@ def test_get_events_succeeds(self, mock_request_method):
6060
"action": {
6161
"id": "evt_action_123",
6262
"name": "house.created",
63-
"project_id": "project_123",
63+
"environment_id": "environment_123",
6464
},
6565
"type": "C",
6666
"actor_name": "Daiki Miyagi",
@@ -92,7 +92,7 @@ def test_get_events_correctly_includes_occured_at_filter(
9292
"action": {
9393
"id": "evt_action_123",
9494
"name": "house.created",
95-
"project_id": "project_123",
95+
"environment_id": "environment_123",
9696
},
9797
"type": "C",
9898
"actor_name": "Daiki Miyagi",
@@ -136,7 +136,7 @@ def test_get_events_correctly_includes_occurred_at_gte(
136136
"action": {
137137
"id": "evt_action_123",
138138
"name": "house.created",
139-
"project_id": "project_123",
139+
"environment_id": "environment_123",
140140
},
141141
"type": "C",
142142
"actor_name": "Daiki Miyagi",
@@ -173,7 +173,7 @@ def test_get_events_correctly_includes_occured_at_lte(
173173
"action": {
174174
"id": "evt_action_123",
175175
"name": "house.created",
176-
"project_id": "project_123",
176+
"environment_id": "environment_123",
177177
},
178178
"type": "C",
179179
"actor_name": "Daiki Miyagi",

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def setup(self):
1616
def test_initialize_sso(self, set_api_key_and_project_id):
1717
assert bool(client.sso)
1818

19-
def test_initialize_audit_log(self, set_api_key_and_project_id):
19+
def test_initialize_audit_log(self, set_api_key):
2020
assert bool(client.audit_trail)
2121

2222
def test_initialize_directory_sync(self, set_api_key):
@@ -37,7 +37,7 @@ def test_initialize_sso_missing_api_key(self, set_project_id):
3737
assert "api_key" in message
3838
assert "project_id" not in message
3939

40-
def test_initialize_sso_missing_project_id(self, set_api_key):
40+
def test_initialize_sso_missing_client_id(self, set_api_key):
4141
with pytest.raises(ConfigurationException) as ex:
4242
client.sso
4343

workos/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55

66
api_key = os.getenv("WORKOS_API_KEY")
77
project_id = os.getenv("WORKOS_PROJECT_ID")
8+
client_id = os.getenv("WORKOS_CLIENT_ID")
89
base_api_url = "https://api.workos.com/"

workos/audit_trail.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def create_event(self, event, idempotency_key=None):
2828
Args:
2929
event (dict) - An event object
3030
event[action] (str) - Specific activity performed by the actor.
31-
event[action_type] (str) - Corresponding CRUD category of the
31+
event[action_type] (str) - Corresponding CRUD category of the
3232
event. Can be one of C, R, U, or D.
3333
event[actor_name] (str) - Display name of the entity performing the action
3434
event[actor_id] (str) - Unique identifier of the entity performing the action
3535
event[group] (str) - A single organization containing related .
3636
members. This will normally be the customer of a vendor's application
37-
event[location] (str) - Identifier for where the event
37+
event[location] (str) - Identifier for where the event
3838
originated. This will be an IP address (IPv4 or IPv6),
3939
hostname, or device ID.
4040
event[occurred_at] (str) - ISO-8601 datetime at which the event

workos/resources/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class WorkOSBaseResource(object):
22
"""Representation of a WorkOS Resource as returned through the API.
3-
3+
44
Attributes:
55
OBJECT_FIELDS (list): List of fields a Resource is comprised of.
66
"""
@@ -25,7 +25,7 @@ def construct_from_response(cls, response):
2525

2626
def to_dict(self):
2727
"""Returns a dict representation of the WorkOSBaseResource.
28-
28+
2929
Returns:
3030
dict: A dict representation of the WorkOSBaseResource
3131
"""

workos/resources/event.py

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

55
class WorkOSEvent(WorkOSBaseResource):
66
"""Representation of an Event as returned by WorkOS through the Audit Trail feature.
7-
7+
88
Attributes:
99
OBJECT_FIELDS (list): List of fields a WorkOSEvent is comprised of.
1010
"""

workos/resources/event_action.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33

44
class WorkOSEventAction(WorkOSBaseResource):
55
"""Representation of an Event Action as returned by WorkOS through the Audit Trail feature.
6-
6+
77
Attributes:
88
OBJECT_FIELDS (list): List of fields a WorkOSEventAction is comprised of.
99
"""
1010

11-
OBJECT_FIELDS = [
12-
"id",
13-
"name",
14-
"project_id",
15-
]
11+
OBJECT_FIELDS = ["id", "name", "environment_id"]

workos/sso.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_authorization_url(
5050
str: URL to redirect a User to to begin the OAuth workflow with WorkOS
5151
"""
5252
params = {
53-
"client_id": workos.project_id,
53+
"client_id": workos.client_id,
5454
"redirect_uri": redirect_uri,
5555
"response_type": RESPONSE_TYPE_CODE,
5656
}
@@ -69,6 +69,13 @@ def get_authorization_url(
6969
if state is not None:
7070
params["state"] = state
7171

72+
if workos.project_id is not None:
73+
params["client_id"] = workos.project_id
74+
warn(
75+
"'project_id' is deprecated. Use 'client_id' instead.",
76+
DeprecationWarning,
77+
)
78+
7279
prepared_request = Request(
7380
"GET",
7481
self.request_helper.generate_api_url(AUTHORIZATION_PATH),
@@ -90,12 +97,19 @@ def get_profile(self, code):
9097
WorkOSProfile: WorkOSProfile object representing the User
9198
"""
9299
params = {
93-
"client_id": workos.project_id,
100+
"client_id": workos.client_id,
94101
"client_secret": workos.api_key,
95102
"code": code,
96103
"grant_type": OAUTH_GRANT_TYPE,
97104
}
98105

106+
if workos.project_id is not None:
107+
params["client_id"] = workos.project_id
108+
warn(
109+
"'project_id' is deprecated. Use 'client_id' instead.",
110+
DeprecationWarning,
111+
)
112+
99113
response = self.request_helper.request(
100114
TOKEN_PATH, method=REQUEST_METHOD_POST, params=params
101115
)
@@ -109,7 +123,7 @@ def promote_draft_connection(self, token):
109123
been promoted will enable Enterprise users of the domain to begin signing in via SSO.
110124
111125
Args:
112-
token (str): The token supplied via the response when a draft connection is created via
126+
token (str): The token supplied via the response when a draft connection is created via
113127
the WorkOS.js embed
114128
115129
Returns:

0 commit comments

Comments
 (0)