-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-8356: Reworked `Ibexa\Core\MVC\Symfony\Security\Authentication\Au…
…thenticatorInterface` usages to comply with Symfony-based authentication (#67) * IBX-8356: Reworked Ibexa\Core\MVC\Symfony\Security\Authentication\AuthenticatorInterface usages to comply with Symfony-based authentication * fixed phpstan * improved code according to PHPStan reports * restored mutation and moved authorization elsewhere * fixed lack of proper password validation * cr remark
- Loading branch information
1 parent
7b178b1
commit ba5e369
Showing
6 changed files
with
75 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\GraphQL\Mutation; | ||
|
||
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use Ibexa\Contracts\Core\Repository\UserService; | ||
use Ibexa\Core\MVC\Symfony\Security\User; | ||
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface; | ||
use Overblog\GraphQLBundle\Definition\Argument; | ||
|
||
final readonly class AuthenticationMutation | ||
{ | ||
public function __construct( | ||
private JWTTokenManagerInterface $tokenManager, | ||
private UserService $userService | ||
) { | ||
} | ||
|
||
/** | ||
* @return array<string, ?string> | ||
* | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException | ||
*/ | ||
public function createToken(Argument $args): array | ||
{ | ||
if (!isset($args['username'], $args['password'])) { | ||
return [ | ||
'message' => 'Missing username or password', | ||
'token' => null, | ||
]; | ||
} | ||
|
||
try { | ||
$user = $this->userService->loadUserByLogin($args['username']); | ||
} catch (NotFoundException) { | ||
return $this->getWrongCredentialsErrorMessage(); | ||
} | ||
|
||
if (!$this->userService->checkUserCredentials($user, $args['password'])) { | ||
return $this->getWrongCredentialsErrorMessage(); | ||
} | ||
|
||
return [ | ||
'token' => $this->tokenManager->create(new User($user)), | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, ?string> | ||
*/ | ||
private function getWrongCredentialsErrorMessage(): array | ||
{ | ||
return [ | ||
'message' => 'Wrong username or password', | ||
'token' => null, | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters