Skip to content

Commit 51e57fe

Browse files
committed
restored mutation and moved authorization elsewhere
1 parent f654f6f commit 51e57fe

File tree

6 files changed

+75
-214
lines changed

6 files changed

+75
-214
lines changed

src/bundle/Resources/config/graphql/PlatformMutation.types.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ PlatformMutation:
2424
language:
2525
type: RepositoryLanguage!
2626
description: "The language the content items must be created in"
27+
createToken:
28+
type: CreatedTokenPayload
29+
resolve: '@=mutation("CreateToken", args)'
30+
args:
31+
username:
32+
type: String!
33+
password:
34+
type: String!
2735

2836
UploadedFilesPayload:
2937
type: object
@@ -44,3 +52,13 @@ DeleteContentPayload:
4452
id:
4553
type: ID
4654
description: "Global ID"
55+
56+
CreatedTokenPayload:
57+
type: object
58+
config:
59+
fields:
60+
token:
61+
type: String
62+
message:
63+
type: String
64+
description: "The reason why authentication has failed, if it has"

src/bundle/Resources/config/services/resolvers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ services:
6262
tags:
6363
- { name: overblog_graphql.resolver, alias: "Thumbnail", method: "resolveThumbnail" }
6464

65+
Ibexa\GraphQL\Mutation\AuthenticationMutation:
66+
tags:
67+
- { name: overblog_graphql.mutation, alias: "CreateToken", method: "createToken" }
68+
6569
Ibexa\GraphQL\Mutation\UploadFiles:
6670
arguments:
6771
$repository: '@ibexa.siteaccessaware.repository'

src/bundle/Resources/config/services/services.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,3 @@ services:
5050
$contentLoader: '@Ibexa\GraphQL\DataLoader\ContentLoader'
5151
tags:
5252
- { name: ibexa.field_type.image_asset.mapper.strategy, priority: 0 }
53-
54-
Ibexa\GraphQL\Security\JWTAuthenticator:
55-
arguments:
56-
$userProvider: '@ibexa.security.user_provider'
57-
58-
Ibexa\GraphQL\Security\JWTTokenMutationFormatEventSubscriber:
59-
tags:
60-
- name: kernel.event_subscriber
61-
dispatcher: security.event_dispatcher.ibexa_jwt_graphql
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\GraphQL\Mutation;
10+
11+
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
12+
use Ibexa\Contracts\Core\Repository\UserService;
13+
use Ibexa\Core\MVC\Symfony\Security\User;
14+
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
15+
use Overblog\GraphQLBundle\Definition\Argument;
16+
17+
final readonly class AuthenticationMutation
18+
{
19+
public function __construct(
20+
private JWTTokenManagerInterface $tokenManager,
21+
private UserService $userService
22+
) {
23+
}
24+
25+
/**
26+
* @return array<string, ?string>
27+
*
28+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
29+
*/
30+
public function createToken(Argument $args): array
31+
{
32+
if (!isset($args['username'], $args['password'])) {
33+
return [
34+
'message' => 'Missing username or password',
35+
'token' => null,
36+
];
37+
}
38+
39+
try {
40+
$user = $this->userService->loadUserByLogin($args['username']);
41+
$this->userService->checkUserCredentials($user, $args['password']);
42+
} catch (NotFoundException) {
43+
return [
44+
'message' => 'Wrong username or password',
45+
'token' => null,
46+
];
47+
}
48+
49+
return [
50+
'token' => $this->tokenManager->create(new User($user)),
51+
];
52+
}
53+
}

src/lib/Security/JWTAuthenticator.php

Lines changed: 0 additions & 149 deletions
This file was deleted.

src/lib/Security/JWTTokenMutationFormatEventSubscriber.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)