You are here

RefreshToken.php in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same filename and directory in other branches
  1. 8.2 simple_oauth_extras/src/Plugin/Oauth2Grant/RefreshToken.php

File

simple_oauth_extras/src/Plugin/Oauth2Grant/RefreshToken.php
View source
<?php

namespace Drupal\simple_oauth_extras\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;

/**
 * @Oauth2Grant(
 *   id = "refresh_token",
 *   label = @Translation("Refresh Token")
 * )
 */
class RefreshToken extends Oauth2GrantBase {

  /**
   * @var \League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface
   */
  protected $refreshTokenRepository;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Class constructor.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Classes

Namesort descending Description
RefreshToken Plugin annotation @Oauth2Grant( id = "refresh_token", label = @Translation("Refresh Token") )