RefreshTokenGrantService.php in OAuth2 Client 8.3
File
src/Service/Grant/RefreshTokenGrantService.php
View source
<?php
namespace Drupal\oauth2_client\Service\Grant;
use League\OAuth2\Client\Token\AccessTokenInterface;
class RefreshTokenGrantService extends Oauth2ClientGrantServiceBase {
public function getAccessToken($pluginId) {
$accessToken = $this
->retrieveAccessToken($pluginId);
if ($accessToken instanceof AccessTokenInterface) {
$expirationTimestamp = $accessToken
->getExpires();
if (!empty($expirationTimestamp) && $accessToken
->hasExpired()) {
$provider = $this
->getProvider($pluginId);
$newAccessToken = $provider
->getAccessToken('refresh_token', [
'refresh_token' => $accessToken
->getRefreshToken(),
]);
$this
->storeAccessToken($pluginId, $newAccessToken);
}
}
}
public function getGrantProvider($pluginId) {
return $this
->getProvider($pluginId);
}
}