Skip to content

Commit 2744d29

Browse files
Add get_profile method and unit test (#83)
* Add get_profile method and unit test
1 parent 5c1e671 commit 2744d29

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tests/test_sso.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ def test_get_profile_and_token_returns_expected_workosprofile_object(
214214
assert profile_and_token.access_token == "01DY34ACQTM3B1CSX1YSZ8Z00D"
215215
assert profile_and_token.profile.to_dict() == mock_profile
216216

217+
def test_get_profile(self, setup_with_client_id, mock_profile, mock_request_method):
218+
mock_request_method("get", mock_profile, 200)
219+
220+
profile = self.sso.get_profile(123)
221+
222+
assert profile.to_dict() == mock_profile
223+
217224
def test_get_connection(
218225
self, setup_with_client_id, mock_connection, mock_request_method
219226
):

workos/sso.py

Lines changed: 21 additions & 1 deletion
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 WorkOSProfileAndToken
8+
from workos.resources.sso import WorkOSProfile, WorkOSProfileAndToken
99
from workos.utils.connection_types import ConnectionType
1010
from workos.utils.request import (
1111
RequestHelper,
@@ -18,6 +18,7 @@
1818

1919
AUTHORIZATION_PATH = "sso/authorize"
2020
TOKEN_PATH = "sso/token"
21+
PROFILE_PATH = "sso/profile"
2122

2223
OAUTH_GRANT_TYPE = "authorization_code"
2324

@@ -86,6 +87,25 @@ def get_authorization_url(
8687

8788
return prepared_request.url
8889

90+
def get_profile(self, accessToken):
91+
"""
92+
Verify that SSO has been completed successfully and retrieve the identity of the user.
93+
94+
Args:
95+
accessToken (str): the token used to authenticate the API call
96+
97+
Returns:
98+
WorkOSProfile
99+
"""
100+
101+
token = accessToken
102+
103+
response = self.request_helper.request(
104+
PROFILE_PATH, method=REQUEST_METHOD_GET, token=token
105+
)
106+
107+
return WorkOSProfile.construct_from_response(response)
108+
89109
def get_profile_and_token(self, code):
90110
"""Get the profile of an authenticated User
91111

0 commit comments

Comments
 (0)