Skip to content

Commit 02169d4

Browse files
committed
Preparing split of core component
1 parent d390f88 commit 02169d4

File tree

8 files changed

+1762
-56
lines changed

8 files changed

+1762
-56
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014-2017 Spomky-Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PHP JWT Core Component
2+
======================
3+
4+
If you really love that project, then you can help me out for a couple of :beers:!
5+
6+
[![Beerpay](https://beerpay.io/Spomky-Labs/jose/badge.svg?style=beer-square)](https://beerpay.io/Spomky-Labs/jose) [![Beerpay](https://beerpay.io/Spomky-Labs/jose/make-wish.svg?style=flat-square)](https://beerpay.io/Spomky-Labs/jose?focus=wish)
7+
8+
---
9+
10+
# Contributing
11+
12+
Requests for new features, bug fixed and all other ideas to make this framework useful are welcome.
13+
If you feel comfortable writing code, you could try to fix [opened issues where help is wanted](https://github.com/web-token/jwt-framework/labels/help+wanted) or [those that are easy to fix](https://github.com/web-token/jwt-framework/labels/easy-pick).
14+
15+
Do not forget to [follow these best practices](.github/CONTRIBUTING.md).
16+
17+
**If you think you have found a security issue, DO NOT open an issue**. You should submit your issue here.
18+
19+
# Licence
20+
21+
This software is release under [MIT licence](LICENSE).

Tests/FooAlgorithm.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* The MIT License (MIT)
7+
*
8+
* Copyright (c) 2014-2017 Spomky-Labs
9+
*
10+
* This software may be modified and distributed under the terms
11+
* of the MIT license. See the LICENSE file for details.
12+
*/
13+
14+
namespace Jose\Component\Core\Tests;
15+
16+
use Jose\Component\Core\AlgorithmInterface;
17+
18+
/**
19+
* Class FooAlgorithm.
20+
*/
21+
final class FooAlgorithm implements AlgorithmInterface
22+
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function name(): string
27+
{
28+
return 'foo';
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function allowedKeyTypes(): array
35+
{
36+
return ['FOO'];
37+
}
38+
}

Tests/JWAManagerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
use Jose\Component\Core\AlgorithmInterface;
1717
use Jose\Component\Core\AlgorithmManager;
18-
use Jose\Component\Signature\Algorithm\HS512;
19-
use Jose\Component\Signature\Algorithm\RS256;
2018
use PHPUnit\Framework\TestCase;
2119

2220
/**
@@ -41,12 +39,12 @@ public function testCreateManagerWithBadList()
4139
*/
4240
public function testCreateManagerAndRetrieveAlgorithm()
4341
{
44-
$manager = AlgorithmManager::create([new HS512(), new RS256()]);
42+
$manager = AlgorithmManager::create([new FooAlgorithm()]);
4543

46-
self::assertEquals(['HS512', 'RS256'], $manager->list());
47-
self::assertTrue($manager->has('HS512'));
44+
self::assertEquals(['foo'], $manager->list());
45+
self::assertTrue($manager->has('foo'));
4846
self::assertFalse($manager->has('HS384'));
49-
self::assertInstanceOf(AlgorithmInterface::class, $manager->get('HS512'));
47+
self::assertInstanceOf(AlgorithmInterface::class, $manager->get('foo'));
5048
$manager->get('HS384');
5149
}
5250
}

Tests/JWKSetTest.php

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use Jose\Component\Core\JWK;
1717
use Jose\Component\Core\JWKSet;
18-
use Jose\Component\Signature\Algorithm\RS256;
1918
use PHPUnit\Framework\TestCase;
2019

2120
/**
@@ -38,15 +37,13 @@ public function testKeySelectionWithAlgorithm()
3837
{
3938
$jwkset = $this->getPublicKeySet();
4039

41-
$jwk = $jwkset->selectKey('sig', new RS256());
40+
$jwk = $jwkset->selectKey('enc', new FooAlgorithm());
4241
self::assertInstanceOf(JWK::class, $jwk);
4342
self::assertEquals([
4443
'kid' => '71ee230371d19630bc17fb90ccf20ae632ad8cf8',
45-
'kty' => 'RSA',
46-
'alg' => 'RS256',
47-
'use' => 'sig',
48-
'n' => 'vnMTRCMvsS04M1yaKR112aB8RxOkWHFixZO68wCRlVLxK4ugckXVD_Ebcq-kms1T2XpoWntVfBuX40r2GvcD9UsTFt_MZlgd1xyGwGV6U_tfQUll5mKxCPjr60h83LXKJ_zmLXIqkV8tAoIg78a5VRWoms_0Bn09DKT3-RBWFjk=',
49-
'e' => 'AQAB',
44+
'kty' => 'FOO',
45+
'alg' => 'foo',
46+
'use' => 'enc',
5047
],
5148
$jwk->all()
5249
);
@@ -56,15 +53,13 @@ public function testKeySelectionWithAlgorithmAndKeyId()
5653
{
5754
$jwkset = $this->getPublicKeySet();
5855

59-
$jwk = $jwkset->selectKey('sig', new RS256(), ['kid' => '02491f945c951adf156f370788e8ccdabf8877a8']);
56+
$jwk = $jwkset->selectKey('sig', new FooAlgorithm(), ['kid' => '02491f945c951adf156f370788e8ccdabf8877a8']);
6057
self::assertInstanceOf(JWK::class, $jwk);
6158
self::assertEquals([
6259
'kid' => '02491f945c951adf156f370788e8ccdabf8877a8',
63-
'kty' => 'RSA',
64-
'alg' => 'RS256',
60+
'kty' => 'FOO',
61+
'alg' => 'foo',
6562
'use' => 'sig',
66-
'n' => 'rI67uHIDWDgCy_Ut-FhhjTCkEcqzoO80IRgdpk_fJHlDmXhMTJKPizxbIEMs0wRHRZpwH-4D20thpnQB5Mgx6-XM9kOvcYpHSdcYME77BwX6uQG-hw2w77NOhYiCSZCLzx-5ld5Wjy0dympL-ExqQw-wrWipMX7NQhIbJqVbZ18=',
67-
'e' => 'AQAB',
6863
],
6964
$jwk->all()
7065
);
@@ -78,11 +73,9 @@ public function testKeySelectionWithKeyId()
7873
self::assertInstanceOf(JWK::class, $jwk);
7974
self::assertEquals([
8075
'kid' => '02491f945c951adf156f370788e8ccdabf8877a8',
81-
'kty' => 'RSA',
82-
'alg' => 'RS256',
76+
'kty' => 'FOO',
77+
'alg' => 'foo',
8378
'use' => 'sig',
84-
'n' => 'rI67uHIDWDgCy_Ut-FhhjTCkEcqzoO80IRgdpk_fJHlDmXhMTJKPizxbIEMs0wRHRZpwH-4D20thpnQB5Mgx6-XM9kOvcYpHSdcYME77BwX6uQG-hw2w77NOhYiCSZCLzx-5ld5Wjy0dympL-ExqQw-wrWipMX7NQhIbJqVbZ18=',
85-
'e' => 'AQAB',
8679
],
8780
$jwk->all()
8881
);
@@ -100,11 +93,9 @@ public function testCreateKeySetFromValues()
10093
{
10194
$values = ['keys' => [[
10295
'kid' => '71ee230371d19630bc17fb90ccf20ae632ad8cf8',
103-
'kty' => 'RSA',
104-
'alg' => 'RS256',
96+
'kty' => 'FOO',
97+
'alg' => 'foo',
10598
'use' => 'sig',
106-
'n' => 'vnMTRCMvsS04M1yaKR112aB8RxOkWHFixZO68wCRlVLxK4ugckXVD_Ebcq-kms1T2XpoWntVfBuX40r2GvcD9UsTFt_MZlgd1xyGwGV6U_tfQUll5mKxCPjr60h83LXKJ_zmLXIqkV8tAoIg78a5VRWoms_0Bn09DKT3-RBWFjk=',
107-
'e' => 'AQAB',
10899
]]];
109100
$jwkset = JWKSet::createFromKeyData($values);
110101
self::assertInstanceOf(JWKSet::class, $jwkset);
@@ -121,47 +112,22 @@ private function getPublicKeySet(): JWKSet
121112
$keys = ['keys' => [
122113
[
123114
'kid' => '71ee230371d19630bc17fb90ccf20ae632ad8cf8',
124-
'kty' => 'RSA',
125-
'alg' => 'RS256',
126-
'use' => 'sig',
127-
'n' => 'vnMTRCMvsS04M1yaKR112aB8RxOkWHFixZO68wCRlVLxK4ugckXVD_Ebcq-kms1T2XpoWntVfBuX40r2GvcD9UsTFt_MZlgd1xyGwGV6U_tfQUll5mKxCPjr60h83LXKJ_zmLXIqkV8tAoIg78a5VRWoms_0Bn09DKT3-RBWFjk=',
128-
'e' => 'AQAB',
115+
'kty' => 'FOO',
116+
'alg' => 'foo',
117+
'use' => 'enc',
129118
],
130119
[
131120
'kid' => '02491f945c951adf156f370788e8ccdabf8877a8',
132-
'kty' => 'RSA',
133-
'alg' => 'RS256',
121+
'kty' => 'FOO',
122+
'alg' => 'foo',
134123
'use' => 'sig',
135-
'n' => 'rI67uHIDWDgCy_Ut-FhhjTCkEcqzoO80IRgdpk_fJHlDmXhMTJKPizxbIEMs0wRHRZpwH-4D20thpnQB5Mgx6-XM9kOvcYpHSdcYME77BwX6uQG-hw2w77NOhYiCSZCLzx-5ld5Wjy0dympL-ExqQw-wrWipMX7NQhIbJqVbZ18=',
136-
'e' => 'AQAB',
137-
],
138-
[
139-
'kty' => 'RSA',
140-
'n' => 'oahUIoWw0K0usKNuOR6H4wkf4oBUXHTxRvgb48E-BVvxkeDNjbC4he8rUWcJoZmds2h7M70imEVhRU5djINXtqllXI4DFqcI1DgjT9LewND8MW2Krf3Spsk_ZkoFnilakGygTwpZ3uesH-PFABNIUYpOiN15dsQRkgr0vEhxN92i2asbOenSZeyaxziK72UwxrrKoExv6kc5twXTq4h-QChLOln0_mtUZwfsRaMStPs6mS6XrgxnxbWhojf663tuEQueGC-FCMfra36C9knDFGzKsNa7LZK2djYgyD3JR_MB_4NUJW_TqOQtwHYbxevoJArm-L5StowjzGy-_bq6Gw',
141-
'e' => 'AQAB',
142-
],
143-
[
144-
'kty' => 'RSA',
145-
'n' => 'sXchDaQebHnPiGvyDOAT4saGEUetSyo9MKLOoWFsueri23bOdgWp4Dy1WlUzewbgBHod5pcM9H95GQRV3JDXboIRROSBigeC5yjU1hGzHHyXss8UDprecbAYxknTcQkhslANGRUZmdTOQ5qTRsLAt6BTYuyvVRdhS8exSZEy_c4gs_7svlJJQ4H9_NxsiIoLwAEk7-Q3UXERGYw_75IDrGA84-lA_-Ct4eTlXHBIY2EaV7t7LjJaynVJCpkv4LKjTTAumiGUIuQhrNhZLuF_RJLqHpM2kgWFLU7-VTdL1VbC2tejvcI2BlMkEpk1BzBZI0KQB0GaDWFLN-aEAw3vRw',
146-
'e' => 'AQAB',
147-
],
148-
[
149-
'kty' => 'RSA',
150-
'n' => 'ofgWCuLjybRlzo0tZWJjNiuSfb4p4fAkd_wWJcyQoTbji9k0l8W26mPddxHmfHQp-Vaw-4qPCJrcS2mJPMEzP1Pt0Bm4d4QlL-yRT-SFd2lZS-pCgNMsD1W_YpRPEwOWvG6b32690r2jZ47soMZo9wGzjb_7OMg0LOL-bSf63kpaSHSXndS5z5rexMdbBYUsLA9e-KXBdQOS-UTo7WTBEMa2R2CapHg665xsmtdVMTBQY4uDZlxvb3qCo5ZwKh9kG4LT6_I5IhlJH7aGhyxXFvUK-DWNmoudF8NAco9_h9iaGNj8q2ethFkMLs91kzk2PAcDTW9gb54h4FRWyuXpoQ',
151-
'e' => 'AQAB',
152124
],
153125
[
154126
'kty' => 'EC',
155127
'crv' => 'P-256',
156128
'x' => 'f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU',
157129
'y' => 'x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0',
158130
],
159-
[
160-
'kty' => 'EC',
161-
'crv' => 'P-521',
162-
'x' => 'AekpBQ8ST8a8VcfVOTNl353vSrDCLLJXmPk06wTjxrrjcBpXp5EOnYG_NjFZ6OvLFV1jSfS9tsz4qUxcWceqwQGk',
163-
'y' => 'ADSmRA43Z1DSNx_RvcLI87cdL07l6jQyyBXMoxVg_l2Th-x3S1WDhjDly79ajL4Kkd0AZMaZmh9ubmf63e3kyMj2',
164-
],
165131
]];
166132

167133
return JWKSet::createFromKeyData($keys);

composer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "web-token/jwt-core",
3+
"description": "Core component of the JWT Framework.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": ["JWS", "JWT", "JWE", "JWA", "JWK", "JWKSet", "Jot", "Jose", "RFC7515", "RFC7516", "RFC7517", "RFC7518", "RFC7519", "RFC7520", "Bundle", "Symfony"],
7+
"homepage": "https://github.com/web-token/jwt-core",
8+
"authors": [
9+
{
10+
"name": "Florent Morselli",
11+
"homepage": "https://github.com/Spomky"
12+
},{
13+
"name": "All contributors",
14+
"homepage": "https://github.com/web-token/jwt-core/contributors"
15+
}
16+
],
17+
"autoload": {
18+
"psr-4": {
19+
"Jose\\Component\\Core\\": ""
20+
}
21+
},
22+
"require": {
23+
"php": "^7.1",
24+
"ext-gmp": "*",
25+
"ext-mbstring": "*",
26+
"fgrosse/phpasn1": "^2.0",
27+
"spomky-labs/base64url": "^1.0"
28+
},
29+
"require-dev": {
30+
"phpunit/phpunit": "^6.0"
31+
},
32+
"extra": {
33+
"branch-alias": {
34+
"dev-master": "1.0.x-dev"
35+
}
36+
},
37+
"config": {
38+
"sort-packages": true
39+
}
40+
}

0 commit comments

Comments
 (0)