Skip to content

Commit

Permalink
Plugin: OAuth2: Fix catch BadMethodCallException when refreshing toke…
Browse files Browse the repository at this point in the history
…n - refs BT#19734
  • Loading branch information
AngelFQC committed Jul 22, 2022
1 parent 65bfb3e commit 9388a5d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions plugin/oauth2/index.php
Expand Up @@ -8,6 +8,10 @@
*/

/** @var OAuth2 $oAuth2Plugin */

use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessToken;

$oAuth2Plugin = OAuth2::create();

if ($oAuth2Plugin->get(OAuth2::SETTING_ENABLE) === 'true') {
Expand All @@ -30,19 +34,16 @@
}

if (ChamiloSession::has('oauth2AccessToken')) {
$accessToken = new \League\OAuth2\Client\Token\AccessToken(ChamiloSession::read('oauth2AccessToken'));
$accessToken = new AccessToken(ChamiloSession::read('oauth2AccessToken'));
if ($accessToken->hasExpired()) {
$provider = $oAuth2Plugin->getProvider();
try {
try {
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $accessToken->getRefreshToken(),
]);
} catch (BadMethodCallException $exception) {
online_logout(null, true);
}
$newAccessToken = $provider->getAccessToken(
'refresh_token',
['refresh_token' => $accessToken->getRefreshToken()]
);
ChamiloSession::write('oauth2AccessToken', $newAccessToken->jsonSerialize());
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $exception) {
} catch (IdentityProviderException|\BadMethodCallException $e) {
online_logout(null, true);
}
}
Expand Down

0 comments on commit 9388a5d

Please sign in to comment.