![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-integration/Model/OpaqueToken/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Integration\Model\OpaqueToken; use Magento\Authorization\Model\UserContextInterface; use Magento\Integration\Api\Data\UserTokenParametersInterface; use Magento\Integration\Api\Exception\UserTokenException; use Magento\Integration\Api\UserTokenIssuerInterface; use Magento\Integration\Model\Oauth\Token; use Magento\Integration\Model\Oauth\TokenFactory as TokenModelFactory; use Magento\Framework\Oauth\Helper\Oauth as OauthHelper; /** * Issues opaque tokens (legacy). */ class Issuer implements UserTokenIssuerInterface { /** * @var TokenModelFactory */ private $tokenFactory; /** * @var OauthHelper */ private $helper; /** * @param TokenModelFactory $tokenFactory */ public function __construct(TokenModelFactory $tokenFactory, OauthHelper $helper) { $this->tokenFactory = $tokenFactory; $this->helper = $helper; } /** * @inheritDoc */ public function create(UserContextInterface $userContext, UserTokenParametersInterface $params): string { /** @var Token $token */ $token = $this->tokenFactory->create(); if ($userContext->getUserType() === UserContextInterface::USER_TYPE_CUSTOMER) { $token->setCustomerId($userContext->getUserId()); } elseif ($userContext->getUserType() === UserContextInterface::USER_TYPE_ADMIN) { $token->setAdminId($userContext->getUserId()); } else { throw new UserTokenException('Can only create tokens for customers and admin users'); } $token->setUserType($userContext->getUserType()); $token->setType(Token::TYPE_ACCESS); $token->setToken($this->helper->generateToken()); $token->setSecret($this->helper->generateTokenSecret()); if ($params->getForcedIssuedTime()) { if ($params->getForcedIssuedTime()->getTimezone()->getName() !== 'UTC') { throw new UserTokenException('Invalid forced issued time provided'); } $token->setCreatedAt($params->getForcedIssuedTime()->format('Y-m-d H:i:s')); } $token = $token->save(); return $token->getToken(); } }