Skip to content

Commit ea92f9b

Browse files
author
ogorkun
committed
MC-38539: Introduce JWT wrapper
1 parent 1e8d3c0 commit ea92f9b

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\JwtFrameworkAdapter\Model;
10+
11+
use Jose\Easy\AlgorithmProvider;
12+
13+
class AlgorithmProviderFactory
14+
{
15+
/**
16+
* Create provider instance.
17+
*
18+
* @param string[] $algorithms Algorithm classes.
19+
* @return AlgorithmProvider
20+
*/
21+
public function create(array $algorithms): AlgorithmProvider
22+
{
23+
return new AlgorithmProvider($algorithms);
24+
}
25+
}

app/code/Magento/JwtFrameworkAdapter/Model/JweAlgorithmManagerFactory.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace Magento\JwtFrameworkAdapter\Model;
1010

1111
use Jose\Component\Core\AlgorithmManager;
12-
use Jose\Easy\AlgorithmProvider;
1312

1413
class JweAlgorithmManagerFactory
1514
{
@@ -32,8 +31,17 @@ class JweAlgorithmManagerFactory
3231
\Jose\Component\Encryption\Algorithm\KeyEncryption\PBES2HS512A256KW::class
3332
];
3433

34+
/**
35+
* @var AlgorithmProviderFactory
36+
*/
37+
private $algorithmProviderFactory;
38+
39+
public function __construct(AlgorithmProviderFactory $algorithmProviderFactory) {
40+
$this->algorithmProviderFactory = $algorithmProviderFactory;
41+
}
42+
3543
public function create(): AlgorithmManager
3644
{
37-
return new AlgorithmManager((new AlgorithmProvider(self::ALGOS))->getAvailableAlgorithms());
45+
return new AlgorithmManager($this->algorithmProviderFactory->create(self::ALGOS)->getAvailableAlgorithms());
3846
}
3947
}

app/code/Magento/JwtFrameworkAdapter/Model/JweCompressionManagerFactory.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@
99
namespace Magento\JwtFrameworkAdapter\Model;
1010

1111
use Jose\Component\Encryption\Compression\CompressionMethodManager;
12-
use Jose\Component\Encryption\Compression\Deflate;
1312

1413
class JweCompressionManagerFactory
1514
{
15+
/**
16+
* @var \Jose\Component\Encryption\Compression\CompressionMethod[]
17+
*/
18+
private $methods;
19+
20+
/**
21+
* @param \Jose\Component\Encryption\Compression\CompressionMethod[] $methods
22+
*/
23+
public function __construct(array $methods)
24+
{
25+
$this->methods = $methods;
26+
}
27+
1628
public function create(): CompressionMethodManager
1729
{
18-
return new CompressionMethodManager([new Deflate()]);
30+
return new CompressionMethodManager($this->methods);
1931
}
2032
}

app/code/Magento/JwtFrameworkAdapter/Model/JweContentAlgorithmManagerFactory.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace Magento\JwtFrameworkAdapter\Model;
1010

1111
use Jose\Component\Core\AlgorithmManager;
12-
use Jose\Easy\AlgorithmProvider;
1312

1413
class JweContentAlgorithmManagerFactory
1514
{
@@ -22,8 +21,17 @@ class JweContentAlgorithmManagerFactory
2221
\Jose\Component\Encryption\Algorithm\ContentEncryption\A256GCM::class,
2322
];
2423

24+
/**
25+
* @var AlgorithmProviderFactory
26+
*/
27+
private $algorithmProviderFactory;
28+
29+
public function __construct(AlgorithmProviderFactory $algorithmProviderFactory) {
30+
$this->algorithmProviderFactory = $algorithmProviderFactory;
31+
}
32+
2533
public function create(): AlgorithmManager
2634
{
27-
return new AlgorithmManager((new AlgorithmProvider(self::ALGOS))->getAvailableAlgorithms());
35+
return new AlgorithmManager($this->algorithmProviderFactory->create(self::ALGOS)->getAvailableAlgorithms());
2836
}
2937
}

app/code/Magento/JwtFrameworkAdapter/Model/JwsAlgorithmManagerFactory.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ class JwsAlgorithmManagerFactory
3131
\Jose\Component\Signature\Algorithm\None::class
3232
];
3333

34+
/**
35+
* @var AlgorithmProviderFactory
36+
*/
37+
private $algorithmProviderFactory;
38+
39+
public function __construct(AlgorithmProviderFactory $algorithmProviderFactory) {
40+
$this->algorithmProviderFactory = $algorithmProviderFactory;
41+
}
42+
3443
public function create(): AlgorithmManager
3544
{
36-
return new AlgorithmManager((new AlgorithmProvider(self::ALGOS))->getAvailableAlgorithms());
45+
return new AlgorithmManager($this->algorithmProviderFactory->create(self::ALGOS)->getAvailableAlgorithms());
3746
}
3847
}

app/code/Magento/JwtFrameworkAdapter/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\Framework\Jwt\JwtManagerInterface" type="Magento\JwtFrameworkAdapter\Model\JwtManager" />
10+
<type name="Magento\JwtFrameworkAdapter\Model\JweCompressionManagerFactory">
11+
<arguments>
12+
<argument name="methods" xsi:type="array">
13+
<item name="deflate" xsi:type="object">Jose\Component\Encryption\Compression\Deflate</item>
14+
</argument>
15+
</arguments>
16+
</type>
1017
</config>

0 commit comments

Comments
 (0)