public function KeyListController::listKeys in JSON Web Token Authentication (JWT) 8
List keys.
Return value
array Return render array.
1 string reference to 'KeyListController::listKeys'
- users_jwt.routing.yml in modules/
users_jwt/ users_jwt.routing.yml - modules/users_jwt/users_jwt.routing.yml
File
- modules/
users_jwt/ src/ Controller/ KeyListController.php, line 47
Class
- KeyListController
- Class KeyListController.
Namespace
Drupal\users_jwt\ControllerCode
public function listKeys(UserInterface $user) {
$keys = $this->keyRepository
->getUsersKeys($user
->id());
$options = $this->keyRepository
->algorithmOptions();
$header = [
$this
->t('Key ID'),
$this
->t('Key Type'),
$this
->t('Key'),
$this
->t('Operations'),
];
$rows = [];
foreach ($keys as $key) {
$row = [
'id' => $key->id,
'alg' => $options[$key->alg] ?? $key->alg,
'pubkey' => Unicode::truncate($key->pubkey, 40, FALSE, TRUE),
];
$row['operations']['data'] = [
'#type' => 'dropbutton',
'#links' => [
'edit' => [
'title' => $this
->t('Edit'),
'url' => Url::fromRoute('users_jwt.key_edit_form', [
'user' => $key->uid,
'key_id' => $key->id,
]),
],
'delete' => [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('users_jwt.key_delete_form', [
'user' => $key->uid,
'key_id' => $key->id,
]),
],
],
];
$rows[] = $row;
}
return [
'#cache' => [
'tags' => [
'users_jwt:' . $user
->id(),
],
],
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this
->t('No keys found.'),
];
}