You are here

public function RestfulTokenAuthController::generateAccessToken in RESTful 7

Create a new access_token entity with a referenced refresh_token.

Parameters

int $uid: The user ID.

Return value

\RestfulTokenAuth The created entity.

File

modules/restful_token_auth/includes/RestfulTokenAuthController.php, line 19
Contains \RestfulTokenAuthController

Class

RestfulTokenAuthController
@file Contains \RestfulTokenAuthController

Code

public function generateAccessToken($uid) {
  $refresh_token = $this
    ->generateRefreshToken($uid);

  // Create a new access token.
  $values = array(
    'uid' => $uid,
    'type' => 'access_token',
    'created' => REQUEST_TIME,
    'name' => t('Access token for: @uid', array(
      '@uid' => $uid,
    )),
    'token' => drupal_random_key(),
    'expire' => $this
      ->getExpireTime(),
    'refresh_token_reference' => array(
      LANGUAGE_NONE => array(
        array(
          'target_id' => $refresh_token->id,
        ),
      ),
    ),
  );
  $access_token = $this
    ->create($values);
  $this
    ->save($access_token);
  return $access_token;
}