You are here

public function AccessTokenUserList::tokenList in Simple OAuth (OAuth2) & OpenID Connect 8

Provide a list of tokens.

1 string reference to 'AccessTokenUserList::tokenList'
simple_oauth.routing.yml in ./simple_oauth.routing.yml
simple_oauth.routing.yml

File

src/Controller/AccessTokenUserList.php, line 14

Class

AccessTokenUserList

Namespace

Drupal\simple_oauth\Controller

Code

public function tokenList(User $user) {
  $entity_type = 'access_token';
  $storage = $this
    ->entityManager()
    ->getStorage($entity_type);
  $ids = $storage
    ->getQuery()
    ->condition('auth_user_id', $user
    ->id())
    ->execute();
  if (empty($ids)) {
    return [
      '#markup' => $this
        ->t('There are no tokens for this user.'),
    ];
  }
  $view_controller = $this
    ->entityManager()
    ->getViewBuilder($entity_type);
  $tokens = $storage
    ->loadMultiple($ids);
  return $view_controller
    ->viewMultiple($tokens);
}