Skip to content

Commit 8764bce

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

2 files changed

Lines changed: 33 additions & 12 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: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,20 @@ public function testGetProfileAndTokenReturnsProfileWithExpectedValues()
118118
public function testGetProfileReturnsProfileWithExpectedValues()
119119
{
120120
$path = "sso/profile";
121+
$token = 'token';
121122

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

124125
$this->mockRequest(
125126
Client::METHOD_GET,
126127
$path,
128+
['Authorization: Bearer ' . $token],
127129
null,
128-
null,
129-
true,
130+
false,
130131
$result
131132
);
132133

133-
$profile = $this->sso->getProfile();
134+
$profile = $this->sso->getProfile($token);
134135
$profileFixture = $this->profileFixture();
135136

136137
$this->assertEquals($profileFixture, $profile->toArray());
@@ -280,6 +281,31 @@ private function profileFixture()
280281
];
281282
}
282283

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

0 commit comments

Comments
 (0)