You are here

public function Storage::setAuthorizationCode in OAuth2 Server 7

File

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

Class

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

Namespace

Drupal\oauth2_server

Code

public function setAuthorizationCode($code, $client_key, $uid, $redirect_uri, $expires, $scope = null, $id_token = null) {
  $client = oauth2_server_client_load($client_key);
  if (!$client) {
    throw new \InvalidArgumentException("The supplied client couldn't be loaded.");
  }

  // If no code was found, start with a new entity.
  $authorization_code = oauth2_server_authorization_code_load($code);
  if (!$authorization_code) {
    $user = user_load($uid);
    if (!$user) {
      throw new \InvalidArgumentException("The supplied user couldn't be loaded.");
    }
    $authorization_code = entity_create('oauth2_server_authorization_code', array());
    $authorization_code->client_id = $client->client_id;
    $authorization_code->uid = $uid;
    $authorization_code->code = $code;
    $authorization_code->id_token = $id_token;
  }
  $authorization_code->redirect_uri = $redirect_uri;
  $authorization_code->expires = $expires;
  $this
    ->setScopeData($authorization_code, $client->server, $scope);
  $status = $authorization_code
    ->save();
  return $status;
}