getIsGuest()) { return null; } $bearer = $this->getBearerToken(); if ($bearer === null) { return null; } try { $token = Yii::$app->tokens->parse($bearer); } catch (InvalidArgumentException $e) { return null; } $sessionId = $token->getClaim('jti', false); if ($sessionId === false) { return null; } return AccountSession::findOne($sessionId); } public function terminateSessions(Account $account, int $mode = 0): void { $currentSession = null; if ($mode & self::KEEP_CURRENT_SESSION) { $currentSession = $this->getActiveSession(); } if (!($mode & self::KEEP_SITE_SESSIONS)) { foreach ($account->sessions as $session) { if ($currentSession === null || $currentSession->id !== $session->id) { $session->delete(); } } } if (!($mode & self::KEEP_MINECRAFT_SESSIONS)) { foreach ($account->minecraftAccessKeys as $minecraftAccessKey) { $minecraftAccessKey->delete(); } } } private function getBearerToken(): ?string { $authHeader = Yii::$app->request->getHeaders()->get('Authorization'); if ($authHeader === null || !preg_match('/^Bearer\s+(.*?)$/', $authHeader, $matches)) { return null; } return $matches[1]; } }