Hash existing API keys, and do checks against the hash

This commit is contained in:
Alejandro Celaya
2024-11-05 23:23:06 +01:00
parent 9f6975119e
commit 1b9c8377ae
5 changed files with 61 additions and 10 deletions

View File

@@ -44,8 +44,7 @@ class ApiKey extends AbstractEntity
*/
public static function fromMeta(ApiKeyMeta $meta): self
{
// $apiKey = new self(self::hashKey($meta->key), $meta->name, $meta->expirationDate);
$apiKey = new self($meta->key, $meta->name, $meta->expirationDate);
$apiKey = new self(self::hashKey($meta->key), $meta->name, $meta->expirationDate);
foreach ($meta->roleDefinitions as $roleDefinition) {
$apiKey->registerRole($roleDefinition);
}

View File

@@ -67,8 +67,7 @@ readonly class ApiKeyService implements ApiKeyServiceInterface
private function getByKey(string $key): ApiKey|null
{
return $this->em->getRepository(ApiKey::class)->findOneBy([
// 'key' => ApiKey::hashKey($key),
'key' => $key,
'key' => ApiKey::hashKey($key),
]);
}
}