Skip to content

Commit

Permalink
Fix error on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Jacobs committed Aug 26, 2019
1 parent 667a840 commit 37b991b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Security/Logout/LogoutHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(FasOpenIdOAuthClient $oauthClient)
public function logout(Request $request, Response $response, TokenInterface $token): void
{
if ($token instanceof FasOpenIdUserToken) {
$this->oauthClient->logOut($token->getOauthToken()->getIdToken());
$this->oauthClient->logOut($token->getOauthToken());
}
}
}
21 changes: 17 additions & 4 deletions Service/FasOpenIdOAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Intracto\FasOpenIdBundle\Service;

use Intracto\FasOpenIdBundle\Model\OAuthToken;
use Intracto\FasOpenIdBundle\Model\OAuthTokenInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -27,6 +28,7 @@ class FasOpenIdOAuthClient
public const ACR_VALUES_SELF_REGISTRATION = 'urn:be:fedict:iam:fas:Level100';

private const GRANT_TYPE_AUTHORIZATION_CODE = 'authorization_code';
private const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';

/**
* @var array
Expand Down Expand Up @@ -201,9 +203,13 @@ public function getUserInfo(OAuthToken $oauthToken): ?string
return null;
}

public function logOut(string $idToken): void
public function logOut(OAuthTokenInterface $oauthToken): void
{
$response = $this->httpClient->request('GET', 'connect/endSession', ['query' => ['id_token_hint' => $idToken]]);
if ($oauthToken->getExpiresIn() < new \DateTime()) {
}
$oauthToken = $this->getRefreshToken($oauthToken->getRefreshToken());

$response = $this->httpClient->request('GET', 'connect/endSession', ['query' => ['id_token_hint' => $oauthToken->getIdToken()]]);

if (Response::HTTP_NO_CONTENT !== $response->getStatusCode()) {
$this->logger->error($response->getInfo('debug'), ['status_code' => $response->getStatusCode()]);
Expand Down Expand Up @@ -247,8 +253,15 @@ public static function getAllPossibleScopes(): array

private function getRefreshToken(string $refreshToken): ?OAuthToken
{
$requestBody = json_encode(['grant_type' => self::GRANT_TYPE_REFRESH_TOKEN, 'refresh_token' => $refreshToken]);
$response = $this->httpClient->request('POST', 'access_token', ['auth_basic' => [$this->clientId, $this->clientSecret], 'body' => $requestBody]);
$requestBody = [
'grant_type' => self::GRANT_TYPE_REFRESH_TOKEN,
'refresh_token' => $refreshToken,
];

$response = $this->httpClient->request('POST', 'access_token', [
'body' => $requestBody,
'auth_basic' => [$this->clientId, $this->clientSecret],
]);

if (Response::HTTP_OK === $response->getStatusCode()) {
return $this->createAccessTokenFromResponse($response->toArray(false));
Expand Down

0 comments on commit 37b991b

Please sign in to comment.