initialState->provideInitialState( 'app_tokens', $this->getAppTokens() ); $this->initialState->provideInitialState( 'can_create_app_token', $this->userSession->getImpersonatingUserID() === null ); return new TemplateResponse('settings', 'settings/personal/security/authtokens'); } public function getSection(): string { return 'security'; } public function getPriority(): int { return 100; } private function getAppTokens(): array { $tokens = $this->tokenProvider->getTokenByUser($this->userId); try { $sessionId = $this->session->getId(); } catch (SessionNotAvailableException $ex) { return []; } try { $sessionToken = $this->tokenProvider->getToken($sessionId); } catch (InvalidTokenException $ex) { return []; } return array_map(function (IToken $token) use ($sessionToken) { $data = $token->jsonSerialize(); $data['canDelete'] = true; $data['canRename'] = $token instanceof INamedToken && $data['type'] !== IToken::WIPE_TOKEN; if ($sessionToken->getId() === $token->getId()) { $data['canDelete'] = false; $data['canRename'] = false; $data['current'] = true; } return $data; }, $tokens); } }