You are here

public function Oauth2GrantManager::getAuthorizationServer in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/Oauth2GrantManager.php \Drupal\simple_oauth\Plugin\Oauth2GrantManager::getAuthorizationServer()
  2. 8.2 src/Plugin/Oauth2GrantManager.php \Drupal\simple_oauth\Plugin\Oauth2GrantManager::getAuthorizationServer()
  3. 5.x src/Plugin/Oauth2GrantManager.php \Drupal\simple_oauth\Plugin\Oauth2GrantManager::getAuthorizationServer()

Gets the authorization server.

Parameters

string $grant_type: The grant type used as plugin ID.

Return value

\League\OAuth2\Server\AuthorizationServer The authorization server.

Throws

\League\OAuth2\Server\Exception\OAuthServerException When the grant cannot be found.

Overrides Oauth2GrantManagerInterface::getAuthorizationServer

File

src/Plugin/Oauth2GrantManager.php, line 120

Class

Oauth2GrantManager
Provides the OAuth2 Grant plugin manager.

Namespace

Drupal\simple_oauth\Plugin

Code

public function getAuthorizationServer($grant_type) {
  try {

    /** @var \Drupal\simple_oauth\Plugin\Oauth2GrantInterface $plugin */
    $plugin = $this
      ->createInstance($grant_type);
  } catch (PluginNotFoundException $exception) {
    throw OAuthServerException::invalidGrant('Check the configuration to see if the grant is enabled.');
  }
  $this
    ->checkKeyPaths();
  $salt = Settings::getHashSalt();

  // The hash salt must be at least 32 characters long.
  if (Core::ourStrlen($salt) < 32) {
    throw OAuthServerException::serverError('Hash salt must be at least 32 characters long.');
  }
  $server = new AuthorizationServer($this->clientRepository, $this->accessTokenRepository, $this->scopeRepository, realpath($this->privateKeyPath), Core::ourSubstr($salt, 0, 32), $this->responseType);

  // Enable the password grant on the server with a token TTL of X hours.
  $server
    ->enableGrantType($plugin
    ->getGrantType(), $this->expiration);
  return $server;
}