Relay on lib to verify JWT expiry

This commit is contained in:
Matej Bačo
2024-05-28 10:59:53 +00:00
parent b1ff989c3f
commit 711e26c605
8 changed files with 16 additions and 36 deletions
+1 -17
View File
@@ -1200,7 +1200,7 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons
$authJWT = $request->getHeader('x-appwrite-jwt', '');
if (!empty($authJWT) && !$project->isEmpty()) { // JWT authentication
$jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 3600, 10); // Instantiate with key, algo, maxAge and leeway.
$jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 3600, 0);
try {
$payload = $jwt->decode($authJWT);
@@ -1218,22 +1218,6 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons
if (empty($user->find('$id', $jwtSessionId, 'sessions'))) { // Match JWT to active token
$user = new Document([]);
}
$exp = $payload['exp'] ?? '';
// Fallback to 15m, just in case
if(empty($exp)) {
$jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway.
try {
$payload = $jwt->decode($authJWT);
} catch (JWTException $error) {
$user = new Document([]);
}
} else {
if($exp < \time()) {
$user = new Document([]);
}
}
}
$dbForProject->setMetadata('user', $user->getId());