Skip to content

Commit

Permalink
User collection->filter instead of array_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoLouwerse committed Jan 26, 2024
1 parent 815bc4d commit 52fcc66
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions api/src/Security/ApiKeyAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,22 @@ public function authenticate(Request $request): PassportInterface
}

try {
$user = $application->getOrganization()->getUsers()[0];
$user = $application->getOrganization()->getUsers()->first();

$users = array_filter($application->getOrganization()->getUsers(), function (User $user) {
$userCollection = $application->getOrganization()->getUsers();
$users = $userCollection->filter(function (User $user) {
return $user->getName() === 'APIKEY_USER';
});
if (empty($users[0]) === false) {
$user = $users[0];

if (count($users) > 0) {
$user = $users->first();
}
} catch (\Exception $exception) {
throw new AuthenticationException('An invalid User is configured for this ApiKey');
throw new AuthenticationException('An invalid User (or no user) is configured for this ApiKey');
}

if ($user instanceof User === false) {
throw new AuthenticationException('An invalid User is configured for this ApiKey');
throw new AuthenticationException('An invalid User (or no user) is configured for this ApiKey');
}

// Set apiKey Application id in session
Expand Down

0 comments on commit 52fcc66

Please sign in to comment.