Spamworldpro Mini Shell
Spamworldpro


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-jwt-user-token/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-jwt-user-token/Model/ConfigurableJwtSettingsProvider.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

declare(strict_types=1);

namespace Magento\JwtUserToken\Model;

use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\Jwt\EncryptionSettingsInterface;
use Magento\Framework\Jwt\Jwe\JweEncryptionJwks;
use Magento\Framework\Jwt\Jwk;
use Magento\Framework\Jwt\JwkSet;
use Magento\Framework\Jwt\Jws\JwsSignatureJwks;
use Magento\JwtUserToken\Api\ConfigReaderInterface;

/**
 * Provides JWT settings based on Magento config.
 */
class ConfigurableJwtSettingsProvider implements JwtSettingsProviderInterface
{
    /**
     * @var EncryptionSettingsInterface[][]
     */
    private $jwsEncryptions;

    /**
     * @var EncryptionSettingsInterface[][]
     */
    private $jweEncryptions;

    /**
     * @var SecretBasedJwksFactory
     */
    private $secretBasedJwkFactory;

    /**
     * @var ConfigReaderInterface
     */
    private $configReader;

    /**
     * @param SecretBasedJwksFactory $secretBasedJwkFactory
     * @param ConfigReaderInterface $configReader
     * @param EncryptionSettingsInterface[][] $jwsEncryptions Additional JWS settings.
     * @param EncryptionSettingsInterface[][] $jweEncryptions Additional JWE settings.
     */
    public function __construct(
        SecretBasedJwksFactory $secretBasedJwkFactory,
        ConfigReaderInterface $configReader,
        array $jwsEncryptions = [],
        array $jweEncryptions = []
    ) {
        $this->jwsEncryptions = $jwsEncryptions;
        $this->jweEncryptions = $jweEncryptions;
        $this->secretBasedJwkFactory = $secretBasedJwkFactory;
        $this->configReader = $configReader;
    }

    /**
     * @inheritDoc
     */
    public function prepareSettingsFor(UserContextInterface $userContext): EncryptionSettingsInterface
    {
        $settings = $this->prepareAllAccepted();

        return array_pop($settings);
    }

    /**
     * @inheritDoc
     */
    public function prepareAllAccepted(): array
    {
        $algorithm = $this->configReader->getJwtAlgorithm();
        $type = $this->configReader->getJwtAlgorithmType($algorithm);
        if ($type === ConfigReaderInterface::JWT_TYPE_JWS) {
            if (!array_key_exists($algorithm, $this->jwsEncryptions)) {
                //Try to create default settings.
                try {
                    $this->jwsEncryptions[$algorithm] = array_map(
                        function (Jwk $jwk) {
                            return new JwsSignatureJwks($jwk);
                        },
                        $this->secretBasedJwkFactory->createFor($algorithm)
                    );
                } catch (\InvalidArgumentException $exception) {
                    //Failed to create
                }
            }
            if (!array_key_exists($algorithm, $this->jwsEncryptions)) {
                throw new \RuntimeException('JWT settings for algorithm "' .$algorithm .'" not found');
            }

            return $this->jwsEncryptions[$algorithm];
        } else {
            if (!array_key_exists($algorithm, $this->jweEncryptions)) {
                //Try to create default settings.
                try {
                    $contentAlg = $this->configReader->getJweContentAlgorithm();
                    $this->jweEncryptions[$algorithm] = array_map(
                        function (Jwk $jwk) use ($contentAlg) {
                            return new JweEncryptionJwks($jwk, $contentAlg);
                        },
                        $this->secretBasedJwkFactory->createFor($algorithm)
                    );
                } catch (\InvalidArgumentException $exception) {
                    //Failed to create
                }
            }
            if (!array_key_exists($algorithm, $this->jweEncryptions)) {
                throw new \RuntimeException('JWT settings for algorithm "' . $algorithm . '" not found');
            }

            return $this->jweEncryptions[$algorithm];
        }
    }
}

Spamworldpro Mini