You are here

public function AccessTokenController::renew in Access unpublished 8

Renews an access token.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\access_unpublished\Entity\AccessToken $access_token: The access token to renew.

Return value

\Drupal\Core\Ajax\AjaxResponse A replace command to replace the token table.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Core\Entity\EntityStorageException

File

src/Controller/AccessTokenController.php, line 58

Class

AccessTokenController
Controller for the access token handling.

Namespace

Drupal\access_unpublished\Controller

Code

public function renew(Request $request, AccessToken $access_token) {

  // Calculate lifetime of expired token.
  $expire = $access_token
    ->get('expire')->value - $access_token
    ->getChangedTime();
  if ($expire > 0) {
    $expire += $this->time
      ->getRequestTime();
  }
  else {
    $expire = AccessToken::defaultExpiration();
  }
  $access_token
    ->set('expire', $expire);
  $access_token
    ->save();
  return $this
    ->buildResponse($request, $access_token);
}