Skip to content

Commit f0629ff

Browse files
authored
Rename get_profile to get_profile_and_token (#67)
* Rename `get_profile` to `get_profile_and_token` * Construct the correct type * Update import * Format code
1 parent 3b82efc commit f0629ff

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

tests/test_sso.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_authorization_url_has_expected_query_params_with_domain_and_provider(
185185
"state": self.state,
186186
}
187187

188-
def test_get_profile_returns_expected_workosprofile_object(
188+
def test_get_profile_and_token_returns_expected_workosprofile_object(
189189
self, setup_with_client_id, mock_profile, mock_request_method
190190
):
191191
response_dict = {
@@ -209,9 +209,10 @@ def test_get_profile_returns_expected_workosprofile_object(
209209

210210
mock_request_method("post", response_dict, 200)
211211

212-
profile = self.sso.get_profile(123)
212+
profile_and_token = self.sso.get_profile_and_token(123)
213213

214-
assert profile.to_dict() == mock_profile
214+
assert profile_and_token.access_token == "01DY34ACQTM3B1CSX1YSZ8Z00D"
215+
assert profile_and_token.profile.to_dict() == mock_profile
215216

216217
def test_create_connection(
217218
self, setup_with_client_id, mock_request_method, mock_connection

workos/resources/sso.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,35 @@ class WorkOSProfile(WorkOSBaseResource):
1818
"idp_id",
1919
"raw_attributes",
2020
]
21+
22+
23+
class WorkOSProfileAndToken(WorkOSBaseResource):
24+
"""Representation of a User Profile and Access Token as returned by WorkOS through the SSO feature.
25+
26+
Attributes:
27+
OBJECT_FIELDS (list): List of fields a WorkOSProfileAndToken is comprised of.
28+
"""
29+
30+
OBJECT_FIELDS = [
31+
"access_token",
32+
]
33+
34+
@classmethod
35+
def construct_from_response(cls, response):
36+
profile_and_token = super(WorkOSProfileAndToken, cls).construct_from_response(
37+
response
38+
)
39+
40+
profile_and_token.profile = WorkOSProfile.construct_from_response(
41+
response["profile"]
42+
)
43+
44+
return profile_and_token
45+
46+
def to_dict(self):
47+
profile_and_token_dict = super(WorkOSProfileAndToken, self).to_dict()
48+
49+
profile_dict = self.profile.to_dict()
50+
profile_and_token_dict["profile"] = profile_dict
51+
52+
return profile_and_token_dict

workos/sso.py

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

66
import workos
77
from workos.exceptions import ConfigurationException
8-
from workos.resources.sso import WorkOSProfile
8+
from workos.resources.sso import WorkOSProfileAndToken
99
from workos.utils.connection_types import ConnectionType
1010
from workos.utils.request import (
1111
RequestHelper,
@@ -88,7 +88,7 @@ def get_authorization_url(
8888

8989
return prepared_request.url
9090

91-
def get_profile(self, code):
91+
def get_profile_and_token(self, code):
9292
"""Get the profile of an authenticated User
9393
9494
Once authenticated, using the code returned having followed the authorization URL,
@@ -98,7 +98,7 @@ def get_profile(self, code):
9898
code (str): Code returned by WorkOS on completion of OAuth 2.0 workflow
9999
100100
Returns:
101-
WorkOSProfile: WorkOSProfile object representing the User
101+
WorkOSProfileAndToken: WorkOSProfileAndToken object representing the User
102102
"""
103103
params = {
104104
"client_id": workos.client_id,
@@ -111,7 +111,7 @@ def get_profile(self, code):
111111
TOKEN_PATH, method=REQUEST_METHOD_POST, params=params
112112
)
113113

114-
return WorkOSProfile.construct_from_response(response["profile"])
114+
return WorkOSProfileAndToken.construct_from_response(response)
115115

116116
def promote_draft_connection(self, token):
117117
"""Promote a Draft Connection

0 commit comments

Comments
 (0)