RefreshToken.php in Simple OAuth (OAuth2) & OpenID Connect 5.x
File
src/Plugin/Oauth2Grant/RefreshToken.php
View source
<?php
namespace Drupal\simple_oauth\Plugin\Oauth2Grant;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\simple_oauth\Plugin\Oauth2GrantBase;
use League\OAuth2\Server\Grant\RefreshTokenGrant;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RefreshToken extends Oauth2GrantBase {
protected $refreshTokenRepository;
protected $configFactory;
public function __construct(array $configuration, $plugin_id, $plugin_definition, RefreshTokenRepositoryInterface $refresh_token_repository, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->refreshTokenRepository = $refresh_token_repository;
$this->configFactory = $config_factory;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('simple_oauth.repositories.refresh_token'), $container
->get('config.factory'));
}
public function getGrantType() {
$grant = new RefreshTokenGrant($this->refreshTokenRepository);
$settings = $this->configFactory
->get('simple_oauth.settings');
$grant
->setRefreshTokenTTL(new \DateInterval(sprintf('PT%dS', $settings
->get('refresh_token_expiration'))));
return $grant;
}
}