Skip to content

Commit

Permalink
Merge pull request #9 from FlxPeters/master
Browse files Browse the repository at this point in the history
Fix #5 - Expose logout URL
  • Loading branch information
stevenmaguire committed Mar 12, 2018
2 parents 6041863 + 2b73d4f commit e8dfd9b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"keycloak"
],
"require": {
"league/oauth2-client": "^2.0",
"league/oauth2-client": "^2.0 <2.3.0",
"firebase/php-jwt": "^4.0"
},
"require-dev": {
Expand Down
24 changes: 24 additions & 0 deletions src/Provider/Keycloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@ public function getResourceOwnerDetailsUrl(AccessToken $token)
return $this->getBaseUrlWithRealm().'/protocol/openid-connect/userinfo';
}

/**
* Builds the logout URL.
*
* @param array $options
* @return string Authorization URL
*/
public function getLogoutUrl(array $options = [])
{
$base = $this->getBaseLogoutUrl();
$params = $this->getAuthorizationParameters($options);
$query = $this->getAuthorizationQuery($params);
return $this->appendQuery($base, $query);
}

/**
* Get logout url to logout of session token
*
* @return string
*/
private function getBaseLogoutUrl()
{
return $this->getBaseUrlWithRealm() . '/protocol/openid-connect/logout';
}

/**
* Creates base url from provider configuration.
*
Expand Down
12 changes: 12 additions & 0 deletions test/src/Provider/KeycloakTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public function testGetAuthorizationUrl()
$this->assertEquals('/auth/realms/mock_realm/protocol/openid-connect/auth', $uri['path']);
}

public function testGetLogoutUrl()
{
$url = $this->provider->getLogoutUrl();
$uri = parse_url($url);

$this->assertEquals('/auth/realms/mock_realm/protocol/openid-connect/logout', $uri['path']);
}

public function testGetBaseAccessTokenUrl()
{
$params = [];
Expand Down Expand Up @@ -204,10 +212,12 @@ public function testUserDataWithEncryption()
$postResponse = m::mock('Psr\Http\Message\ResponseInterface');
$postResponse->shouldReceive('getBody')->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}');
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'application/x-www-form-urlencoded']);
$postResponse->shouldReceive('getStatusCode')->andReturn(200);

$userResponse = m::mock('Psr\Http\Message\ResponseInterface');
$userResponse->shouldReceive('getBody')->andReturn($jwt);
$userResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'application/jwt']);
$userResponse->shouldReceive('getStatusCode')->andReturn(200);

$decoder = \Mockery::mock('overload:Firebase\JWT\JWT');
$decoder->shouldReceive('decode')->with($jwt, $key, [$algorithm])->andReturn([
Expand Down Expand Up @@ -243,10 +253,12 @@ public function testUserDataFailsWhenEncryptionEncounteredAndNotConfigured()
$postResponse = m::mock('Psr\Http\Message\ResponseInterface');
$postResponse->shouldReceive('getBody')->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}');
$postResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'application/x-www-form-urlencoded']);
$postResponse->shouldReceive('getStatusCode')->andReturn(200);

$userResponse = m::mock('Psr\Http\Message\ResponseInterface');
$userResponse->shouldReceive('getBody')->andReturn(uniqid());
$userResponse->shouldReceive('getHeader')->andReturn(['content-type' => 'application/jwt']);
$userResponse->shouldReceive('getStatusCode')->andReturn(200);

$client = m::mock('GuzzleHttp\ClientInterface');
$client->shouldReceive('send')
Expand Down

0 comments on commit e8dfd9b

Please sign in to comment.