/** * @NoAdminRequired * @NoSubadminRequired * * @return JSONResponse */ public function destroy($id) { $user = $this->userManager->get($this->uid); if (is_null($user)) { return []; } $this->tokenProvider->invalidateTokenById($user, $id); return []; }
/** * Update password of the browser session token if there is one * * @param string $password */ public function updateSessionTokenPassword($password) { try { $sessionId = $this->session->getId(); $token = $this->tokenProvider->getToken($sessionId); $this->tokenProvider->setPassword($token, $sessionId, $password); } catch (SessionNotAvailableException $ex) { // Nothing to do } catch (InvalidTokenException $ex) { // Nothing to do } }
/** * logout the user from the session */ public function logout() { $this->manager->emit('\\OC\\User', 'logout'); $user = $this->getUser(); if (!is_null($user)) { try { $this->tokenProvider->invalidateToken($this->session->getId()); } catch (SessionNotAvailableException $ex) { } } $this->setUser(null); $this->setLoginName(null); $this->unsetMagicInCookie(); $this->session->clear(); }
/** * Generate a new access token clients can authenticate with * * @PublicPage * @NoCSRFRequired * * @param string $user * @param string $password * @param string $name the name of the client * @return JSONResponse */ public function generateToken($user, $password, $name = 'unknown client') { if (is_null($user) || is_null($password)) { $response = new JSONResponse(); $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY); return $response; } $loginName = $user; $user = $this->userManager->checkPassword($loginName, $password); if ($user === false) { $response = new JSONResponse(); $response->setStatus(Http::STATUS_UNAUTHORIZED); return $response; } if ($this->twoFactorAuthManager->isTwoFactorAuthenticated($user)) { $resp = new JSONResponse(); $resp->setStatus(Http::STATUS_UNAUTHORIZED); return $resp; } $token = $this->secureRandom->generate(128); $this->tokenProvider->generateToken($token, $user->getUID(), $loginName, $password, $name, IToken::PERMANENT_TOKEN); return ['token' => $token]; }