Skip to content

Commit

Permalink
restored mutation and moved authorization elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Jun 25, 2024
1 parent f654f6f commit 52e0d1f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 214 deletions.
18 changes: 18 additions & 0 deletions src/bundle/Resources/config/graphql/PlatformMutation.types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ PlatformMutation:
language:
type: RepositoryLanguage!
description: "The language the content items must be created in"
createToken:
type: CreatedTokenPayload
resolve: '@=mutation("CreateToken", args)'
args:
username:
type: String!
password:
type: String!

UploadedFilesPayload:
type: object
Expand All @@ -44,3 +52,13 @@ DeleteContentPayload:
id:
type: ID
description: "Global ID"

CreatedTokenPayload:
type: object
config:
fields:
token:
type: String
message:
type: String
description: "The reason why authentication has failed, if it has"
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/resolvers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ services:
tags:
- { name: overblog_graphql.resolver, alias: "Thumbnail", method: "resolveThumbnail" }

Ibexa\GraphQL\Mutation\AuthenticationMutation:
tags:
- { name: overblog_graphql.mutation, alias: "CreateToken", method: "createToken" }

Ibexa\GraphQL\Mutation\UploadFiles:
arguments:
$repository: '@ibexa.siteaccessaware.repository'
Expand Down
9 changes: 0 additions & 9 deletions src/bundle/Resources/config/services/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,3 @@ services:
$contentLoader: '@Ibexa\GraphQL\DataLoader\ContentLoader'
tags:
- { name: ibexa.field_type.image_asset.mapper.strategy, priority: 0 }

Ibexa\GraphQL\Security\JWTAuthenticator:
arguments:
$userProvider: '@ibexa.security.user_provider'

Ibexa\GraphQL\Security\JWTTokenMutationFormatEventSubscriber:
tags:
- name: kernel.event_subscriber
dispatcher: security.event_dispatcher.ibexa_jwt_graphql
54 changes: 54 additions & 0 deletions src/lib/Mutation/AuthenticationMutation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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();
if (!isset($arguments['username'], $arguments['password'])) {
return [
'message' => 'Missing username or password',
'token' => null,
];
}

try {
$user = $this->userService->loadUserByLogin($arguments['username']);
$this->userService->checkUserCredentials($user, $arguments['password']);
} catch (NotFoundException) {
return [
'message' => 'Wrong username or password',
'token' => null,
];
}

return [
'token' => $this->tokenManager->create(new User($user)),
];
}
}
149 changes: 0 additions & 149 deletions src/lib/Security/JWTAuthenticator.php

This file was deleted.

56 changes: 0 additions & 56 deletions src/lib/Security/JWTTokenMutationFormatEventSubscriber.php

This file was deleted.

0 comments on commit 52e0d1f

Please sign in to comment.