You are here

public function Storage::getRefreshToken in OAuth2 Server 7

File

lib/Drupal/oauth2_server/Storage.php, line 378

Class

Storage
Provides Drupal storage (through the underlying Entity API) for the library.

Namespace

Drupal\oauth2_server

Code

public function getRefreshToken($refresh_token) {
  $token = oauth2_server_token_load($refresh_token);
  if ($token) {
    $token_wrapper = entity_metadata_wrapper('oauth2_server_token', $token);
    $scopes = array();
    foreach ($token_wrapper->scopes as $scope_wrapper) {
      $scopes[] = $scope_wrapper->name
        ->value();
    }

    // Return a token array in the format expected by the library.
    $token = array(
      'server' => $token_wrapper->client->server
        ->raw(),
      'client_id' => $token_wrapper->client->client_key
        ->value(),
      'user_id' => $token_wrapper->user->uid
        ->value(),
      'refresh_token' => $token_wrapper->token
        ->value(),
      'expires' => (int) $token_wrapper->expires
        ->value(),
      'scope' => implode(' ', $scopes),
    );
    if (module_exists('uuid')) {
      $token['user_uuid'] = $token_wrapper->user->uuid
        ->value();
    }
  }
  return $token;
}