You are here

public function OAuth2Storage::getRefreshToken in OAuth2 Server 2.0.x

Same name and namespace in other branches
  1. 8 src/OAuth2Storage.php \Drupal\oauth2_server\OAuth2Storage::getRefreshToken()

Get refresh token.

Parameters

string $refresh_token: The refresh token string.

Return value

array|bool The token array or false.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/OAuth2Storage.php, line 808

Class

OAuth2Storage
Provides Drupal OAuth2 storage for the library.

Namespace

Drupal\oauth2_server

Code

public function getRefreshToken($refresh_token) {

  /** @var \Drupal\oauth2_server\TokenInterface $token */
  $token = $this
    ->getStorageToken($refresh_token);
  if (!$token) {
    return FALSE;
  }
  $user = $token
    ->getUser();
  if ($user && $user
    ->isBlocked()) {

    // If the user is blocked, deny access.
    return FALSE;
  }
  $scopes = [];

  /** @var \Drupal\oauth2_server\ScopeInterface $token */
  $scope_entities = $token->scopes
    ->referencedEntities();
  foreach ($scope_entities as $scope) {
    $scopes[] = $scope->scope_id;
  }
  sort($scopes);
  return [
    'server' => $token
      ->getClient()
      ->getServer()
      ->id(),
    'client_id' => $token
      ->getClient()->client_id,
    'user_id' => $token
      ->getUser()
      ->id(),
    'user_uuid' => $token
      ->getUser()
      ->uuid(),
    'refresh_token' => $token->token->value,
    'expires' => (int) $token->expires->value,
    'scope' => implode(' ', $scopes),
  ];
}