Skip to content

Commit f7dc162

Browse files
author
Sander Verkuil
committed
Work with the proper response structure
1 parent 1a16b28 commit f7dc162

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

lib/SSO.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,16 @@ public function getProfileAndToken($code)
125125
*
126126
* @return Resource\Profile
127127
*/
128-
public function getProfile()
128+
public function getProfile($accessToken)
129129
{
130130
$response = Client::request(
131131
Client::METHOD_GET,
132132
'sso/profile',
133+
["Authorization: Bearer " . $accessToken],
133134
null,
134-
null,
135-
true
136135
);
137136

138-
if (!array_key_exists('profile', $response)) {
139-
throw new Exception\GenericException('The profile was not found in the response.');
140-
}
141-
142-
return Resource\Profile::constructFromResponse($response['profile']);
137+
return Resource\Profile::constructFromResponse($response);
143138
}
144139

145140
/**

tests/WorkOS/SSOTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testGetProfileReturnsProfileWithExpectedValues()
119119
{
120120
$path = "sso/profile";
121121

122-
$result = $this->profileAndTokenResponseFixture();
122+
$result = $this->profileResponseFixture();
123123

124124
$this->mockRequest(
125125
Client::METHOD_GET,
@@ -280,6 +280,31 @@ private function profileFixture()
280280
];
281281
}
282282

283+
private function profileResponseFixture()
284+
{
285+
return json_encode([
286+
"id" => "prof_hen",
287+
"email" => "hen@papagenos.com",
288+
"first_name" => "hen",
289+
"last_name" => "cha",
290+
"organization_id" => "org_01FG7HGMY2CZZR2FWHTEE94VF0",
291+
"connection_id" => "conn_01EMH8WAK20T42N2NBMNBCYHAG",
292+
"connection_type" => "GoogleOAuth",
293+
"idp_id" => "randomalphanum",
294+
"role" => new RoleResponse("admin"),
295+
"groups" => array("Admins", "Developers"),
296+
"custom_attributes" => array("license" => "professional"),
297+
"raw_attributes" => array(
298+
"email" => "hen@papagenos.com",
299+
"first_name" => "hen",
300+
"last_name" => "cha",
301+
"ipd_id" => "randomalphanum",
302+
"groups" => array("Admins", "Developers"),
303+
"license" => "professional"
304+
),
305+
]);
306+
}
307+
283308
private function connectionFixture()
284309
{
285310
return [

0 commit comments

Comments
 (0)