Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions lib/SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,21 @@ public function getProfileAndToken($code)
*
* @return Resource\Profile
*/
public function getProfile($accessToken)
public function getProfile()
{
$getProfilePath = "sso/profile";

$params = [
"access_token" => $accessToken
];

$method = Client::METHOD_GET;

$url = "https://api.workos.com/sso/profile";

$requestHeaders = ["Authorization: Bearer " . $accessToken];

list($result) = Client::requestClient()->request(
$method,
$url,
$requestHeaders,
null
$response = Client::request(
Client::METHOD_GET,
'sso/profile',
null,
null,
true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Document why the 'true' parameter is being passed to request()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not done in other parts of the codebase, so I don't see why I should do it here. Not sure what the maintainers think?

);

$decodedResponse = json_decode($result, true);

$profile = Resource\Profile::constructFromResponse($decodedResponse);
if (!array_key_exists('profile', $response)) {
throw new Exception\GenericException('The profile was not found in the response.');
}

return $profile->json();
return Resource\Profile::constructFromResponse($response['profile']);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions tests/WorkOS/SSOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ public function testGetProfileAndTokenReturnsProfileWithExpectedValues()
$this->assertEquals($profileFixture, $profileAndToken->profile->toArray());
}

public function testGetProfileReturnsProfileWithExpectedValues()
{
$path = "sso/profile";

$result = $this->profileAndTokenResponseFixture();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Using profileAndTokenResponseFixture() for a profile-only test may hide potential issues. Create a separate profileResponseFixture() that matches the actual API response for /sso/profile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this indeed introduced a bug. Had the proper endpoint now.


$this->mockRequest(
Client::METHOD_GET,
$path,
null,
null,
true,
$result
);

$profile = $this->sso->getProfile();
$profileFixture = $this->profileFixture();

$this->assertEquals($profileFixture, $profile->toArray());
}

public function testGetConnection()
{
$connection = "connection_id";
Expand Down