Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 6 additions & 22 deletions lib/SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,14 @@ public function getProfileAndToken($code)
*/
public function getProfile($accessToken)
{
$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',
["Authorization: Bearer " . $accessToken],
null,
);

$decodedResponse = json_decode($result, true);

$profile = Resource\Profile::constructFromResponse($decodedResponse);

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

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

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

$result = $this->profileResponseFixture();

$this->mockRequest(
Client::METHOD_GET,
$path,
['Authorization: Bearer ' . $token],
null,
false,
$result
);

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

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

public function testGetConnection()
{
$connection = "connection_id";
Expand Down Expand Up @@ -259,6 +281,31 @@ private function profileFixture()
];
}

private function profileResponseFixture()
{
return json_encode([
"id" => "prof_hen",
"email" => "[email protected]",
"first_name" => "hen",
"last_name" => "cha",
"organization_id" => "org_01FG7HGMY2CZZR2FWHTEE94VF0",
"connection_id" => "conn_01EMH8WAK20T42N2NBMNBCYHAG",
"connection_type" => "GoogleOAuth",
"idp_id" => "randomalphanum",
"role" => new RoleResponse("admin"),
"groups" => array("Admins", "Developers"),
"custom_attributes" => array("license" => "professional"),
"raw_attributes" => array(
"email" => "[email protected]",
"first_name" => "hen",
"last_name" => "cha",
"ipd_id" => "randomalphanum",
"groups" => array("Admins", "Developers"),
"license" => "professional"
),
]);
}

private function connectionFixture()
{
return [
Expand Down