RevokeCustomerToken.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\CustomerGraphQl\Model\Resolver;
  8. use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
  9. use Magento\Framework\GraphQl\Config\Element\Field;
  10. use Magento\Framework\GraphQl\Query\ResolverInterface;
  11. use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
  12. use Magento\Integration\Api\CustomerTokenServiceInterface;
  13. /**
  14. * Customers Revoke Token resolver, used for GraphQL request processing.
  15. */
  16. class RevokeCustomerToken implements ResolverInterface
  17. {
  18. /**
  19. * @var CheckCustomerAccount
  20. */
  21. private $checkCustomerAccount;
  22. /**
  23. * @var CustomerTokenServiceInterface
  24. */
  25. private $customerTokenService;
  26. /**
  27. * @param CheckCustomerAccount $checkCustomerAccount
  28. * @param CustomerTokenServiceInterface $customerTokenService
  29. */
  30. public function __construct(
  31. CheckCustomerAccount $checkCustomerAccount,
  32. CustomerTokenServiceInterface $customerTokenService
  33. ) {
  34. $this->checkCustomerAccount = $checkCustomerAccount;
  35. $this->customerTokenService = $customerTokenService;
  36. }
  37. /**
  38. * @inheritdoc
  39. */
  40. public function resolve(
  41. Field $field,
  42. $context,
  43. ResolveInfo $info,
  44. array $value = null,
  45. array $args = null
  46. ) {
  47. $currentUserId = $context->getUserId();
  48. $currentUserType = $context->getUserType();
  49. $this->checkCustomerAccount->execute($currentUserId, $currentUserType);
  50. return ['result' => $this->customerTokenService->revokeCustomerAccessToken((int)$currentUserId)];
  51. }
  52. }