diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 324d069841..2c44ffeee5 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1,7 +1,6 @@ throw new Exception(Exception::USER_INVALID_TOKEN) }); + $provider = match ($verifiedToken->getAttribute('type')) { + TOKEN_TYPE_VERIFICATION, + TOKEN_TYPE_RECOVERY, + TOKEN_TYPE_INVITE => SESSION_PROVIDER_EMAIL, + TOKEN_TYPE_MAGIC_URL => SESSION_PROVIDER_MAGIC_URL, + TOKEN_TYPE_PHONE => SESSION_PROVIDER_PHONE, + TOKEN_TYPE_OAUTH2 => SESSION_PROVIDER_OAUTH2, + default => SESSION_PROVIDER_TOKEN, + }; $session = new Document(array_merge( [ '$id' => ID::unique(), 'userId' => $user->getId(), 'userInternalId' => $user->getSequence(), - 'provider' => Auth::getSessionProviderByTokenType($verifiedToken->getAttribute('type')), + 'provider' => $provider, 'secret' => $proofForToken->hash($sessionSecret), // One way hash encryption to protect DB leak 'userAgent' => $request->getUserAgent('UNKNOWN'), 'ip' => $request->getIP(), diff --git a/app/controllers/general.php b/app/controllers/general.php index d5b764091f..8c93728a25 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -4,7 +4,6 @@ require_once __DIR__ . '/../init.php'; use Ahc\Jwt\JWT; use Ahc\Jwt\JWTException; -use Appwrite\Auth\Auth; use Appwrite\Auth\Key; use Appwrite\Event\Certificate; use Appwrite\Event\Event; @@ -223,7 +222,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw */ $requirePreview = \is_null($apiKey) || !$apiKey->isPreviewAuthDisabled(); if ($isPreview && $requirePreview) { - $cookie = $request->getCookie(Auth::$cookieNamePreview, ''); + $cookie = $request->getCookie(COOKIE_NAME_PREVIEW, ''); $authorized = false; // Security checks to mark authorized true @@ -1614,7 +1613,7 @@ App::get('/_appwrite/authorize') $expire = DateTime::formatTz(DateTime::addSeconds(new \DateTime(), $duration)); $response - ->addCookie(Auth::$cookieNamePreview, $jwt, (new \DateTime($expire))->getTimestamp(), '/', $host, ('https' === $protocol), true, null) + ->addCookie(COOKIE_NAME_PREVIEW, $jwt, (new \DateTime($expire))->getTimestamp(), '/', $host, ('https' === $protocol), true, null) ->addHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') ->addHeader('Pragma', 'no-cache') ->redirect($protocol . '://' . $host . $path); diff --git a/app/init/constants.php b/app/init/constants.php index 9f7766040a..0d53d92183 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -350,3 +350,6 @@ const TOKENS_RESOURCE_TYPE_DATABASES = 'databases'; const SCHEDULE_RESOURCE_TYPE_EXECUTION = 'execution'; const SCHEDULE_RESOURCE_TYPE_FUNCTION = 'function'; const SCHEDULE_RESOURCE_TYPE_MESSAGE = 'message'; + +/** Preview cookie */ +const COOKIE_NAME_PREVIEW = 'a_jwt_console'; \ No newline at end of file diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php deleted file mode 100644 index cf82b947f3..0000000000 --- a/src/Appwrite/Auth/Auth.php +++ /dev/null @@ -1,41 +0,0 @@ -