diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php index f4f651f683b8e..98b0975b37169 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php @@ -79,9 +79,9 @@ public function resolve( $currentUserId = $context->getUserId(); $currentUserType = $context->getUserType(); - $currentUserId = (int)$currentUserId; - $this->checkCustomerAccount->execute($currentUserId, $currentUserType); + + $currentUserId = (int)$currentUserId; $this->checkCustomerPassword->execute($args['currentPassword'], $currentUserId); $this->accountManagement->changePasswordById($currentUserId, $args['currentPassword'], $args['newPassword']); diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php index ff958d3733788..5dbdd91a6fef9 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php @@ -55,7 +55,7 @@ public function resolve( $this->checkCustomerAccount->execute($currentUserId, $currentUserType); - $status = $this->subscriberFactory->create()->loadByCustomerId($currentUserId)->isSubscribed(); + $status = $this->subscriberFactory->create()->loadByCustomerId((int)$currentUserId)->isSubscribed(); return (bool)$status; } } diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/RevokeCustomerToken.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/RevokeCustomerToken.php similarity index 59% rename from app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/RevokeCustomerToken.php rename to app/code/Magento/CustomerGraphQl/Model/Resolver/RevokeCustomerToken.php index 7eb219a01217e..d3b16c05a6492 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/Customer/Account/RevokeCustomerToken.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/RevokeCustomerToken.php @@ -5,11 +5,10 @@ */ declare(strict_types=1); -namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account; +namespace Magento\CustomerGraphQl\Model\Resolver; -use Magento\Authorization\Model\UserContextInterface; +use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount; use Magento\Framework\GraphQl\Config\Element\Field; -use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Integration\Api\CustomerTokenServiceInterface; @@ -20,9 +19,9 @@ class RevokeCustomerToken implements ResolverInterface { /** - * @var UserContextInterface + * @var CheckCustomerAccount */ - private $userContext; + private $checkCustomerAccount; /** * @var CustomerTokenServiceInterface @@ -30,14 +29,14 @@ class RevokeCustomerToken implements ResolverInterface private $customerTokenService; /** - * @param UserContextInterface $userContext + * @param CheckCustomerAccount $checkCustomerAccount * @param CustomerTokenServiceInterface $customerTokenService */ public function __construct( - UserContextInterface $userContext, + CheckCustomerAccount $checkCustomerAccount, CustomerTokenServiceInterface $customerTokenService ) { - $this->userContext = $userContext; + $this->checkCustomerAccount = $checkCustomerAccount; $this->customerTokenService = $customerTokenService; } @@ -51,17 +50,11 @@ public function resolve( array $value = null, array $args = null ) { - $customerId = (int)$this->userContext->getUserId(); + $currentUserId = $context->getUserId(); + $currentUserType = $context->getUserType(); - if ($customerId === 0) { - throw new GraphQlAuthorizationException( - __( - 'Current customer does not have access to the resource "%1"', - [\Magento\Customer\Model\Customer::ENTITY] - ) - ); - } + $this->checkCustomerAccount->execute($currentUserId, $currentUserType); - return $this->customerTokenService->revokeCustomerAccessToken($customerId); + return $this->customerTokenService->revokeCustomerAccessToken((int)$currentUserId); } } diff --git a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls index 00db881481ebc..b8411f00c5cb1 100644 --- a/app/code/Magento/CustomerGraphQl/etc/schema.graphqls +++ b/app/code/Magento/CustomerGraphQl/etc/schema.graphqls @@ -9,7 +9,7 @@ type Mutation { generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve Customer token") changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes password for logged in customer") updateCustomer (input: UpdateCustomerInput): UpdateCustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update customer personal information") - revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\RevokeCustomerToken") @doc(description:"Revoke Customer token") + revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke Customer token") } type CustomerToken { diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/RevokeCustomerTokenTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/RevokeCustomerTokenTest.php index dac48bf01e7db..415a81f8cf45a 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/RevokeCustomerTokenTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/RevokeCustomerTokenTest.php @@ -7,6 +7,7 @@ namespace Magento\GraphQl\Customer; +use Magento\Integration\Api\CustomerTokenServiceInterface; use Magento\TestFramework\ObjectManager; use Magento\TestFramework\TestCase\GraphQlAbstract; @@ -16,7 +17,6 @@ class RevokeCustomerTokenTest extends GraphQlAbstract { /** - * Verify customers with valid credentials * @magentoApiDataFixture Magento/Customer/_files/customer.php */ public function testRevokeCustomerTokenValidCredentials() @@ -30,8 +30,7 @@ public function testRevokeCustomerTokenValidCredentials() $userName = 'customer@example.com'; $password = 'password'; /** @var CustomerTokenServiceInterface $customerTokenService */ - $customerTokenService = ObjectManager::getInstance() - ->get(\Magento\Integration\Api\CustomerTokenServiceInterface::class); + $customerTokenService = ObjectManager::getInstance()->get(CustomerTokenServiceInterface::class); $customerToken = $customerTokenService->createCustomerAccessToken($userName, $password); $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; @@ -40,7 +39,8 @@ public function testRevokeCustomerTokenValidCredentials() } /** - * Verify guest customers + * @expectedException \Exception + * @expectedExceptionMessage The current customer isn't authorized. */ public function testRevokeCustomerTokenForGuestCustomer() { @@ -49,11 +49,6 @@ public function testRevokeCustomerTokenForGuestCustomer() revokeCustomerToken } QUERY; - $this->expectException(\Exception::class); - $this->expectExceptionMessage( - 'GraphQL response contains errors: Current customer' . ' ' . - 'does not have access to the resource "customer"' - ); $this->graphQlQuery($query, [], ''); } }