Oauth2ClientServiceBase.php in OAuth2 Client 8.3
File
src/Service/Oauth2ClientServiceBase.php
View source
<?php
namespace Drupal\oauth2_client\Service;
use Drupal\oauth2_client\Exception\InvalidOauth2ClientException;
use League\OAuth2\Client\Token\AccessTokenInterface;
abstract class Oauth2ClientServiceBase implements Oauth2ClientServiceInterface {
protected $oauth2ClientPluginManager;
public function getClient($pluginId) {
$clients =& drupal_static(__CLASS__ . '::' . __FUNCTION__, []);
if (!isset($clients[$pluginId])) {
$definition = $this->oauth2ClientPluginManager
->getDefinition($pluginId);
if (!$definition || !isset($definition['id'])) {
throw new InvalidOauth2ClientException($pluginId);
}
$clients[$pluginId] = $this->oauth2ClientPluginManager
->createInstance($definition['id']);
}
return $clients[$pluginId];
}
public function retrieveAccessToken($pluginId) {
$client = $this
->getClient($pluginId);
$token = $client
->retrieveAccessToken();
if ($token instanceof AccessTokenInterface) {
return $token;
}
return NULL;
}
public function clearAccessToken($pluginId) {
$client = $this
->getClient($pluginId);
$client
->clearAccessToken();
}
}