File tree 12 files changed +57
-38
lines changed
12 files changed +57
-38
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
7
7
## [ Unreleased]
8
8
9
+ ### Added (v9)
10
+ - A CryptKeyInterface to allow developers to change the CryptKey implementation with greater ease (PR #1044 )
11
+
9
12
### Fixed
10
13
- Clients are now explicitly prevented from using the Client Credentials grant unless they are confidential to conform
11
14
with the OAuth2 spec (PR #1035 )
Original file line number Diff line number Diff line change @@ -40,12 +40,12 @@ class AuthorizationServer implements EmitterAwareInterface
40
40
protected $ grantTypeAccessTokenTTL = [];
41
41
42
42
/**
43
- * @var CryptKey
43
+ * @var CryptKeyInterface
44
44
*/
45
45
protected $ privateKey ;
46
46
47
47
/**
48
- * @var CryptKey
48
+ * @var CryptKeyInterface
49
49
*/
50
50
protected $ publicKey ;
51
51
@@ -85,7 +85,7 @@ class AuthorizationServer implements EmitterAwareInterface
85
85
* @param ClientRepositoryInterface $clientRepository
86
86
* @param AccessTokenRepositoryInterface $accessTokenRepository
87
87
* @param ScopeRepositoryInterface $scopeRepository
88
- * @param CryptKey |string $privateKey
88
+ * @param CryptKeyInterface |string $privateKey
89
89
* @param string|Key $encryptionKey
90
90
* @param null|ResponseTypeInterface $responseType
91
91
*/
@@ -101,7 +101,7 @@ public function __construct(
101
101
$ this ->accessTokenRepository = $ accessTokenRepository ;
102
102
$ this ->scopeRepository = $ scopeRepository ;
103
103
104
- if ($ privateKey instanceof CryptKey === false ) {
104
+ if ($ privateKey instanceof CryptKeyInterface === false ) {
105
105
$ privateKey = new CryptKey ($ privateKey );
106
106
}
107
107
Original file line number Diff line number Diff line change 14
14
use Lcobucci \JWT \Parser ;
15
15
use Lcobucci \JWT \Signer \Rsa \Sha256 ;
16
16
use Lcobucci \JWT \ValidationData ;
17
- use League \OAuth2 \Server \CryptKey ;
17
+ use League \OAuth2 \Server \CryptKeyInterface ;
18
18
use League \OAuth2 \Server \CryptTrait ;
19
19
use League \OAuth2 \Server \Exception \OAuthServerException ;
20
20
use League \OAuth2 \Server \Repositories \AccessTokenRepositoryInterface ;
@@ -31,7 +31,7 @@ class BearerTokenValidator implements AuthorizationValidatorInterface
31
31
private $ accessTokenRepository ;
32
32
33
33
/**
34
- * @var CryptKey
34
+ * @var CryptKeyInterface
35
35
*/
36
36
protected $ publicKey ;
37
37
@@ -46,9 +46,9 @@ public function __construct(AccessTokenRepositoryInterface $accessTokenRepositor
46
46
/**
47
47
* Set the public key
48
48
*
49
- * @param CryptKey $key
49
+ * @param CryptKeyInterface $key
50
50
*/
51
- public function setPublicKey (CryptKey $ key )
51
+ public function setPublicKey (CryptKeyInterface $ key )
52
52
{
53
53
$ this ->publicKey = $ key ;
54
54
}
Original file line number Diff line number Diff line change 14
14
use LogicException ;
15
15
use RuntimeException ;
16
16
17
- class CryptKey
17
+ class CryptKey implements CryptKeyInterface
18
18
{
19
19
const RSA_KEY_PATTERN =
20
20
'/^(-----BEGIN (RSA )?(PUBLIC|PRIVATE) KEY-----)\R.*(-----END (RSA )?(PUBLIC|PRIVATE) KEY-----)\R?$/s ' ;
@@ -102,19 +102,15 @@ private function saveKeyToFile($key)
102
102
}
103
103
104
104
/**
105
- * Retrieve key path.
106
- *
107
- * @return string
105
+ * {@inheritdoc}
108
106
*/
109
107
public function getKeyPath ()
110
108
{
111
109
return $ this ->keyPath ;
112
110
}
113
111
114
112
/**
115
- * Retrieve key pass phrase.
116
- *
117
- * @return null|string
113
+ * {@inheritdoc}
118
114
*/
119
115
public function getPassPhrase ()
120
116
{
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace League \OAuth2 \Server ;
4
+
5
+ interface CryptKeyInterface
6
+ {
7
+ /**
8
+ * Retrieve key path.
9
+ *
10
+ * @return string
11
+ */
12
+ public function getKeyPath ();
13
+
14
+ /**
15
+ * Retrieve key pass phrase.
16
+ *
17
+ * @return null|string
18
+ */
19
+ public function getPassPhrase ();
20
+ }
Original file line number Diff line number Diff line change 9
9
10
10
namespace League \OAuth2 \Server \Entities ;
11
11
12
- use League \OAuth2 \Server \CryptKey ;
12
+ use League \OAuth2 \Server \CryptKeyInterface ;
13
13
14
14
interface AccessTokenEntityInterface extends TokenInterface
15
15
{
16
16
/**
17
17
* Set a private key used to encrypt the access token.
18
18
*/
19
- public function setPrivateKey (CryptKey $ privateKey );
19
+ public function setPrivateKey (CryptKeyInterface $ privateKey );
20
20
21
21
/**
22
22
* Generate a string representation of the access token.
Original file line number Diff line number Diff line change 14
14
use Lcobucci \JWT \Signer \Key ;
15
15
use Lcobucci \JWT \Signer \Rsa \Sha256 ;
16
16
use Lcobucci \JWT \Token ;
17
- use League \OAuth2 \Server \CryptKey ;
17
+ use League \OAuth2 \Server \CryptKeyInterface ;
18
18
use League \OAuth2 \Server \Entities \ClientEntityInterface ;
19
19
use League \OAuth2 \Server \Entities \ScopeEntityInterface ;
20
20
21
21
trait AccessTokenTrait
22
22
{
23
23
/**
24
- * @var CryptKey
24
+ * @var CryptKeyInterface
25
25
*/
26
26
private $ privateKey ;
27
27
28
28
/**
29
29
* Set the private key used to encrypt this access token.
30
30
*/
31
- public function setPrivateKey (CryptKey $ privateKey )
31
+ public function setPrivateKey (CryptKeyInterface $ privateKey )
32
32
{
33
33
$ this ->privateKey = $ privateKey ;
34
34
}
35
35
36
36
/**
37
37
* Generate a JWT from the access token
38
38
*
39
- * @param CryptKey $privateKey
39
+ * @param CryptKeyInterface $privateKey
40
40
*
41
41
* @return Token
42
42
*/
43
- private function convertToJWT (CryptKey $ privateKey )
43
+ private function convertToJWT (CryptKeyInterface $ privateKey )
44
44
{
45
45
return (new Builder ())
46
46
->setAudience ($ this ->getClient ()->getIdentifier ())
Original file line number Diff line number Diff line change 15
15
use Error ;
16
16
use Exception ;
17
17
use League \Event \EmitterAwareTrait ;
18
- use League \OAuth2 \Server \CryptKey ;
18
+ use League \OAuth2 \Server \CryptKeyInterface ;
19
19
use League \OAuth2 \Server \CryptTrait ;
20
20
use League \OAuth2 \Server \Entities \AccessTokenEntityInterface ;
21
21
use League \OAuth2 \Server \Entities \AuthCodeEntityInterface ;
@@ -83,7 +83,7 @@ abstract class AbstractGrant implements GrantTypeInterface
83
83
protected $ refreshTokenTTL ;
84
84
85
85
/**
86
- * @var CryptKey
86
+ * @var CryptKeyInterface
87
87
*/
88
88
protected $ privateKey ;
89
89
@@ -151,9 +151,9 @@ public function setRefreshTokenTTL(DateInterval $refreshTokenTTL)
151
151
/**
152
152
* Set the private key
153
153
*
154
- * @param CryptKey $key
154
+ * @param CryptKeyInterface $key
155
155
*/
156
- public function setPrivateKey (CryptKey $ key )
156
+ public function setPrivateKey (CryptKeyInterface $ key )
157
157
{
158
158
$ this ->privateKey = $ key ;
159
159
}
Original file line number Diff line number Diff line change 14
14
use DateInterval ;
15
15
use Defuse \Crypto \Key ;
16
16
use League \Event \EmitterAwareInterface ;
17
- use League \OAuth2 \Server \CryptKey ;
17
+ use League \OAuth2 \Server \CryptKeyInterface ;
18
18
use League \OAuth2 \Server \Repositories \AccessTokenRepositoryInterface ;
19
19
use League \OAuth2 \Server \Repositories \ClientRepositoryInterface ;
20
20
use League \OAuth2 \Server \Repositories \ScopeRepositoryInterface ;
@@ -131,9 +131,9 @@ public function setDefaultScope($scope);
131
131
/**
132
132
* Set the path to the private key.
133
133
*
134
- * @param CryptKey $privateKey
134
+ * @param CryptKeyInterface $privateKey
135
135
*/
136
- public function setPrivateKey (CryptKey $ privateKey );
136
+ public function setPrivateKey (CryptKeyInterface $ privateKey );
137
137
138
138
/**
139
139
* Set the encryption key
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class ResourceServer
23
23
private $ accessTokenRepository ;
24
24
25
25
/**
26
- * @var CryptKey
26
+ * @var CryptKeyInterface
27
27
*/
28
28
private $ publicKey ;
29
29
@@ -36,7 +36,7 @@ class ResourceServer
36
36
* New server instance.
37
37
*
38
38
* @param AccessTokenRepositoryInterface $accessTokenRepository
39
- * @param CryptKey |string $publicKey
39
+ * @param CryptKeyInterface |string $publicKey
40
40
* @param null|AuthorizationValidatorInterface $authorizationValidator
41
41
*/
42
42
public function __construct (
@@ -46,7 +46,7 @@ public function __construct(
46
46
) {
47
47
$ this ->accessTokenRepository = $ accessTokenRepository ;
48
48
49
- if ($ publicKey instanceof CryptKey === false ) {
49
+ if ($ publicKey instanceof CryptKeyInterface === false ) {
50
50
$ publicKey = new CryptKey ($ publicKey );
51
51
}
52
52
$ this ->publicKey = $ publicKey ;
Original file line number Diff line number Diff line change 11
11
12
12
namespace League \OAuth2 \Server \ResponseTypes ;
13
13
14
- use League \OAuth2 \Server \CryptKey ;
14
+ use League \OAuth2 \Server \CryptKeyInterface ;
15
15
use League \OAuth2 \Server \CryptTrait ;
16
16
use League \OAuth2 \Server \Entities \AccessTokenEntityInterface ;
17
17
use League \OAuth2 \Server \Entities \RefreshTokenEntityInterface ;
@@ -31,7 +31,7 @@ abstract class AbstractResponseType implements ResponseTypeInterface
31
31
protected $ refreshToken ;
32
32
33
33
/**
34
- * @var CryptKey
34
+ * @var CryptKeyInterface
35
35
*/
36
36
protected $ privateKey ;
37
37
@@ -54,9 +54,9 @@ public function setRefreshToken(RefreshTokenEntityInterface $refreshToken)
54
54
/**
55
55
* Set the private key
56
56
*
57
- * @param CryptKey $key
57
+ * @param CryptKeyInterface $key
58
58
*/
59
- public function setPrivateKey (CryptKey $ key )
59
+ public function setPrivateKey (CryptKeyInterface $ key )
60
60
{
61
61
$ this ->privateKey = $ key ;
62
62
}
Original file line number Diff line number Diff line change 4
4
5
5
use DateInterval ;
6
6
use League \OAuth2 \Server \AuthorizationServer ;
7
- use League \OAuth2 \Server \CryptKey ;
7
+ use League \OAuth2 \Server \CryptKeyInterface ;
8
8
use League \OAuth2 \Server \Exception \OAuthServerException ;
9
9
use League \OAuth2 \Server \Grant \AuthCodeGrant ;
10
10
use League \OAuth2 \Server \Grant \ClientCredentialsGrant ;
@@ -153,7 +153,7 @@ public function testMultipleRequestsGetDifferentResponseTypeInstances()
153
153
$ encryptionKey = 'file:// ' . __DIR__ . '/Stubs/public.key ' ;
154
154
155
155
$ responseTypePrototype = new class extends BearerTokenResponse {
156
- /* @return null|CryptKey */
156
+ /* @return null|CryptKeyInterface */
157
157
public function getPrivateKey ()
158
158
{
159
159
return $ this ->privateKey ;
You can’t perform that action at this time.
0 commit comments