-
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.
restored mutation and moved authorization elsewhere
- Loading branch information
1 parent
f654f6f
commit f43c65e
Showing
6 changed files
with
79 additions
and
214 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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 | ||
{ | ||
$arguments = $args->getArrayCopy(); | ||
$username = $arguments['username']; | ||
$password = $arguments['password']; | ||
|
||
if (!isset($username, $password)) { | ||
return [ | ||
'message' => 'Missing username or password', | ||
'token' => null, | ||
]; | ||
} | ||
|
||
try { | ||
$user = $this->userService->loadUserByLogin($username); | ||
$this->userService->checkUserCredentials($user, $password); | ||
} catch (NotFoundException) { | ||
return [ | ||
'message' => 'Wrong username or password', | ||
'token' => null, | ||
]; | ||
} | ||
|
||
return [ | ||
'token' => $this->tokenManager->create(new User($user)), | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
src/lib/Security/JWTTokenMutationFormatEventSubscriber.php
This file was deleted.
Oops, something went wrong.