account key support

This commit is contained in:
Matej Bačo
2025-12-23 11:59:38 +01:00
parent 09d71e73af
commit bce3ce85d5
+19
View File
@@ -430,6 +430,25 @@ App::setResource('user', function (string $mode, Document $project, Document $co
}
}
}
// Account based on account API key
$accountKey = $request->getHeader('x-appwrite-key', '');
$accountKeyId = $request->getHeader('x-appwrite-user', '');
if (!empty($accountKeyId) && !empty($accountKey)) {
$accountKeyUser = Authorization::skip(fn () => $dbForPlatform->getDocument('users', $accountKeyId));
if (!$accountKeyUser->isEmpty()) {
$key = $accountKeyUser->find(
key: 'secret',
find: $accountKey,
subject: 'keys'
);
if (!empty($key)) {
$user = $accountKeyUser;
}
}
}
$dbForProject->setMetadata('user', $user->getId());
$dbForPlatform->setMetadata('user', $user->getId());