Skip to content

Commit

Permalink
MC-38539: Introduce JWT wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ogorkun committed Feb 22, 2021
1 parent 1e8d3c0 commit ea92f9b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\JwtFrameworkAdapter\Model;

use Jose\Easy\AlgorithmProvider;

class AlgorithmProviderFactory
{
/**
* Create provider instance.
*
* @param string[] $algorithms Algorithm classes.
* @return AlgorithmProvider
*/
public function create(array $algorithms): AlgorithmProvider
{
return new AlgorithmProvider($algorithms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Magento\JwtFrameworkAdapter\Model;

use Jose\Component\Core\AlgorithmManager;
use Jose\Easy\AlgorithmProvider;

class JweAlgorithmManagerFactory
{
Expand All @@ -32,8 +31,17 @@ class JweAlgorithmManagerFactory
\Jose\Component\Encryption\Algorithm\KeyEncryption\PBES2HS512A256KW::class
];

/**
* @var AlgorithmProviderFactory
*/
private $algorithmProviderFactory;

public function __construct(AlgorithmProviderFactory $algorithmProviderFactory) {
$this->algorithmProviderFactory = $algorithmProviderFactory;
}

public function create(): AlgorithmManager
{
return new AlgorithmManager((new AlgorithmProvider(self::ALGOS))->getAvailableAlgorithms());
return new AlgorithmManager($this->algorithmProviderFactory->create(self::ALGOS)->getAvailableAlgorithms());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
namespace Magento\JwtFrameworkAdapter\Model;

use Jose\Component\Encryption\Compression\CompressionMethodManager;
use Jose\Component\Encryption\Compression\Deflate;

class JweCompressionManagerFactory
{
/**
* @var \Jose\Component\Encryption\Compression\CompressionMethod[]
*/
private $methods;

/**
* @param \Jose\Component\Encryption\Compression\CompressionMethod[] $methods
*/
public function __construct(array $methods)
{
$this->methods = $methods;
}

public function create(): CompressionMethodManager
{
return new CompressionMethodManager([new Deflate()]);
return new CompressionMethodManager($this->methods);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Magento\JwtFrameworkAdapter\Model;

use Jose\Component\Core\AlgorithmManager;
use Jose\Easy\AlgorithmProvider;

class JweContentAlgorithmManagerFactory
{
Expand All @@ -22,8 +21,17 @@ class JweContentAlgorithmManagerFactory
\Jose\Component\Encryption\Algorithm\ContentEncryption\A256GCM::class,
];

/**
* @var AlgorithmProviderFactory
*/
private $algorithmProviderFactory;

public function __construct(AlgorithmProviderFactory $algorithmProviderFactory) {
$this->algorithmProviderFactory = $algorithmProviderFactory;
}

public function create(): AlgorithmManager
{
return new AlgorithmManager((new AlgorithmProvider(self::ALGOS))->getAvailableAlgorithms());
return new AlgorithmManager($this->algorithmProviderFactory->create(self::ALGOS)->getAvailableAlgorithms());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@ class JwsAlgorithmManagerFactory
\Jose\Component\Signature\Algorithm\None::class
];

/**
* @var AlgorithmProviderFactory
*/
private $algorithmProviderFactory;

public function __construct(AlgorithmProviderFactory $algorithmProviderFactory) {
$this->algorithmProviderFactory = $algorithmProviderFactory;
}

public function create(): AlgorithmManager
{
return new AlgorithmManager((new AlgorithmProvider(self::ALGOS))->getAvailableAlgorithms());
return new AlgorithmManager($this->algorithmProviderFactory->create(self::ALGOS)->getAvailableAlgorithms());
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/JwtFrameworkAdapter/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\Jwt\JwtManagerInterface" type="Magento\JwtFrameworkAdapter\Model\JwtManager" />
<type name="Magento\JwtFrameworkAdapter\Model\JweCompressionManagerFactory">
<arguments>
<argument name="methods" xsi:type="array">
<item name="deflate" xsi:type="object">Jose\Component\Encryption\Compression\Deflate</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit ea92f9b

Please sign in to comment.