Password.php in Simple OAuth (OAuth2) & OpenID Connect 5.x
File
src/Plugin/Oauth2Grant/Password.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\PasswordGrant;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Password extends Oauth2GrantBase {
protected $userRepository;
protected $refreshTokenRepository;
protected $configFactory;
public function __construct(array $configuration, $plugin_id, $plugin_definition, UserRepositoryInterface $user_repository, RefreshTokenRepositoryInterface $refresh_token_repository, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->userRepository = $user_repository;
$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.user'), $container
->get('simple_oauth.repositories.refresh_token'), $container
->get('config.factory'));
}
public function getGrantType() {
$grant = new PasswordGrant($this->userRepository, $this->refreshTokenRepository);
$settings = $this->configFactory
->get('simple_oauth.settings');
$grant
->setRefreshTokenTTL(new \DateInterval(sprintf('PT%dS', $settings
->get('refresh_token_expiration'))));
return $grant;
}
}
Classes
Name |
Description |
Password |
Plugin annotation
@Oauth2Grant(
id = "password",
label = @Translation("Password")
) |