Skip to content

Commit ef5ea77

Browse files
authored
Merge pull request #1375 from Sephster/php-8-1-compat
Add Types to the Library
2 parents 0610336 + a116856 commit ef5ea77

File tree

88 files changed

+2092
-2621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2092
-2621
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88
### Added
9+
- GrantTypeInterface has a new function, `revokeRefreshTokens()` for enabling or disabling refresh tokens after use (PR #1375)
910
- A CryptKeyInterface to allow developers to change the CryptKey implementation with greater ease (PR #1044)
1011
- The authorization server can now finalize scopes when a client uses a refresh token (PR #1094)
1112
- An AuthorizationRequestInterface to make it easier to extend the AuthorizationRequest (PR #1110)
13+
- Added function `getKeyContents()` to the `CryptKeyInterface` (PR #1375)
1214

1315
### Fixed
1416
- If a refresh token has expired, been revoked, cannot be decrypted, or does not belong to the correct client, the server will now issue an `invalid_grant` error and a HTTP 400 response. In previous versions the server incorrectly issued an `invalid_request` and HTTP 401 response (PR #1042) (PR #1082)
@@ -17,6 +19,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1719
- Authorization Request objects are now created through the factory method, `createAuthorizationRequest()` (PR #1111)
1820
- Changed parameters for `finalizeScopes()` to allow a reference to an auth code ID (PR #1112)
1921

22+
### Removed
23+
- Removed message property from OAuthException HTTP response. Now just use error_description as per the OAuth 2 spec (PR #1375)
24+
2025
## [8.5.4] - released 2023-08-25
2126
### Added
2227
- Support for league/uri ^7.0 (PR #1367)

composer.json

+18-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
"league/uri": "^6.7 || ^7.0",
1111
"lcobucci/jwt": "^4.3 || ^5.0",
1212
"psr/http-message": "^1.0.1 || ^2.0",
13-
"defuse/php-encryption": "^2.3",
13+
"defuse/php-encryption": "^2.3.1",
1414
"lcobucci/clock": "^2.2 || ^3.0"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^9.6.6",
17+
"phpunit/phpunit": "^9.6.11",
1818
"laminas/laminas-diactoros": "^3.0.0",
19-
"phpstan/phpstan": "^0.12.57",
20-
"phpstan/phpstan-phpunit": "^0.12.16",
21-
"roave/security-advisories": "dev-master"
19+
"phpstan/phpstan": "^1.10.26",
20+
"phpstan/phpstan-phpunit": "^1.3.14",
21+
"roave/security-advisories": "dev-master",
22+
"phpstan/extension-installer": "^1.3",
23+
"phpstan/phpstan-deprecation-rules": "^1.1",
24+
"phpstan/phpstan-strict-rules": "^1.5",
25+
"slevomat/coding-standard": "^8.13",
26+
"php-parallel-lint/php-parallel-lint": "^1.3",
27+
"squizlabs/php_codesniffer": "^3.7"
2228
},
2329
"repositories": [
2430
{
@@ -69,5 +75,12 @@
6975
"psr-4": {
7076
"LeagueTests\\": "tests/"
7177
}
78+
},
79+
"config": {
80+
"allow-plugins": {
81+
"ocramius/package-versions": true,
82+
"phpstan/extension-installer": true,
83+
"dealerdirect/phpcodesniffer-composer-installer": false
84+
}
7285
}
7386
}

phpstan.neon

-8
This file was deleted.

phpstan.neon.dist

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
- tests
6+
ignoreErrors:
7+
-
8+
message: '#Call to an undefined method League\\OAuth2\\Server\\ResponseTypes\\ResponseTypeInterface::getAccessToken\(\)\.#'
9+
path: tests/Grant/ClientCredentialsGrantTest.php
10+
- '#Return type \(League\\Event\\EmitterInterface\|null\) of method LeagueTests\\Stubs\\GrantType::getEmitter\(\) should be covariant with return type \(League\\Event\\EmitterInterface\) of method League\\Event\\EmitterAwareInterface::getEmitter\(\)#'

src/AuthorizationServer.php

+27-91
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @author Alex Bilbie <[email protected]>
45
* @copyright Copyright (c) Alex Bilbie
@@ -7,6 +8,8 @@
78
* @link https://github.com/thephpleague/oauth2-server
89
*/
910

11+
declare(strict_types=1);
12+
1013
namespace League\OAuth2\Server;
1114

1215
use DateInterval;
@@ -32,79 +35,36 @@ class AuthorizationServer implements EmitterAwareInterface
3235
/**
3336
* @var GrantTypeInterface[]
3437
*/
35-
protected $enabledGrantTypes = [];
38+
protected array $enabledGrantTypes = [];
3639

3740
/**
3841
* @var DateInterval[]
3942
*/
40-
protected $grantTypeAccessTokenTTL = [];
43+
protected array $grantTypeAccessTokenTTL = [];
4144

42-
/**
43-
* @var CryptKeyInterface
44-
*/
45-
protected $privateKey;
45+
protected CryptKeyInterface $privateKey;
4646

47-
/**
48-
* @var CryptKeyInterface
49-
*/
50-
protected $publicKey;
47+
protected CryptKeyInterface $publicKey;
5148

52-
/**
53-
* @var ResponseTypeInterface
54-
*/
55-
protected $responseType;
49+
protected ResponseTypeInterface $responseType;
5650

57-
/**
58-
* @var ClientRepositoryInterface
59-
*/
60-
private $clientRepository;
51+
private string|Key $encryptionKey;
6152

62-
/**
63-
* @var AccessTokenRepositoryInterface
64-
*/
65-
private $accessTokenRepository;
53+
private string $defaultScope = '';
6654

67-
/**
68-
* @var ScopeRepositoryInterface
69-
*/
70-
private $scopeRepository;
55+
private bool $revokeRefreshTokens = true;
7156

7257
/**
73-
* @var string|Key
74-
*/
75-
private $encryptionKey;
76-
77-
/**
78-
* @var string
79-
*/
80-
private $defaultScope = '';
81-
82-
/**
83-
* @var bool
84-
*/
85-
private $revokeRefreshTokens = true;
86-
87-
/**
88-
* New server instance.
89-
*
90-
* @param ClientRepositoryInterface $clientRepository
91-
* @param AccessTokenRepositoryInterface $accessTokenRepository
92-
* @param ScopeRepositoryInterface $scopeRepository
93-
* @param CryptKeyInterface|string $privateKey
94-
* @param string|Key $encryptionKey
95-
* @param null|ResponseTypeInterface $responseType
58+
* New server instance
9659
*/
9760
public function __construct(
98-
ClientRepositoryInterface $clientRepository,
99-
AccessTokenRepositoryInterface $accessTokenRepository,
100-
ScopeRepositoryInterface $scopeRepository,
101-
$privateKey,
102-
$encryptionKey,
103-
ResponseTypeInterface $responseType = null
61+
private ClientRepositoryInterface $clientRepository,
62+
private AccessTokenRepositoryInterface $accessTokenRepository,
63+
private ScopeRepositoryInterface $scopeRepository,
64+
CryptKeyInterface|string $privateKey,
65+
Key|string $encryptionKey,
66+
ResponseTypeInterface|null $responseType = null
10467
) {
105-
$this->clientRepository = $clientRepository;
106-
$this->accessTokenRepository = $accessTokenRepository;
107-
$this->scopeRepository = $scopeRepository;
10868

10969
if ($privateKey instanceof CryptKeyInterface === false) {
11070
$privateKey = new CryptKey($privateKey);
@@ -123,12 +83,9 @@ public function __construct(
12383
}
12484

12585
/**
126-
* Enable a grant type on the server.
127-
*
128-
* @param GrantTypeInterface $grantType
129-
* @param null|DateInterval $accessTokenTTL
86+
* Enable a grant type on the server
13087
*/
131-
public function enableGrantType(GrantTypeInterface $grantType, DateInterval $accessTokenTTL = null)
88+
public function enableGrantType(GrantTypeInterface $grantType, DateInterval|null $accessTokenTTL = null): void
13289
{
13390
if ($accessTokenTTL === null) {
13491
$accessTokenTTL = new DateInterval('PT1H');
@@ -150,13 +107,9 @@ public function enableGrantType(GrantTypeInterface $grantType, DateInterval $acc
150107
/**
151108
* Validate an authorization request
152109
*
153-
* @param ServerRequestInterface $request
154-
*
155110
* @throws OAuthServerException
156-
*
157-
* @return AuthorizationRequestInterface
158111
*/
159-
public function validateAuthorizationRequest(ServerRequestInterface $request)
112+
public function validateAuthorizationRequest(ServerRequestInterface $request): AuthorizationRequestInterface
160113
{
161114
foreach ($this->enabledGrantTypes as $grantType) {
162115
if ($grantType->canRespondToAuthorizationRequest($request)) {
@@ -169,16 +122,11 @@ public function validateAuthorizationRequest(ServerRequestInterface $request)
169122

170123
/**
171124
* Complete an authorization request
172-
*
173-
* @param AuthorizationRequestInterface $authRequest
174-
* @param ResponseInterface $response
175-
*
176-
* @return ResponseInterface
177125
*/
178126
public function completeAuthorizationRequest(
179127
AuthorizationRequestInterface $authRequest,
180128
ResponseInterface $response
181-
) {
129+
): ResponseInterface {
182130
return $this->enabledGrantTypes[$authRequest->getGrantTypeId()]
183131
->completeAuthorizationRequest($authRequest)
184132
->generateHttpResponse($response);
@@ -187,39 +135,31 @@ public function completeAuthorizationRequest(
187135
/**
188136
* Return an access token response.
189137
*
190-
* @param ServerRequestInterface $request
191-
* @param ResponseInterface $response
192-
*
193138
* @throws OAuthServerException
194-
*
195-
* @return ResponseInterface
196139
*/
197-
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response)
140+
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
198141
{
199142
foreach ($this->enabledGrantTypes as $grantType) {
200143
if (!$grantType->canRespondToAccessTokenRequest($request)) {
201144
continue;
202145
}
146+
203147
$tokenResponse = $grantType->respondToAccessTokenRequest(
204148
$request,
205149
$this->getResponseType(),
206150
$this->grantTypeAccessTokenTTL[$grantType->getIdentifier()]
207151
);
208152

209-
if ($tokenResponse instanceof ResponseTypeInterface) {
210-
return $tokenResponse->generateHttpResponse($response);
211-
}
153+
return $tokenResponse->generateHttpResponse($response);
212154
}
213155

214156
throw OAuthServerException::unsupportedGrantType();
215157
}
216158

217159
/**
218160
* Get the token type that grants will return in the HTTP response.
219-
*
220-
* @return ResponseTypeInterface
221161
*/
222-
protected function getResponseType()
162+
protected function getResponseType(): ResponseTypeInterface
223163
{
224164
$responseType = clone $this->responseType;
225165

@@ -234,18 +174,14 @@ protected function getResponseType()
234174

235175
/**
236176
* Set the default scope for the authorization server.
237-
*
238-
* @param string $defaultScope
239177
*/
240-
public function setDefaultScope($defaultScope)
178+
public function setDefaultScope(string $defaultScope): void
241179
{
242180
$this->defaultScope = $defaultScope;
243181
}
244182

245183
/**
246184
* Sets whether to revoke refresh tokens or not (for all grant types).
247-
*
248-
* @param bool $revokeRefreshTokens
249185
*/
250186
public function revokeRefreshTokens(bool $revokeRefreshTokens): void
251187
{
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @author Alex Bilbie <[email protected]>
45
* @copyright Copyright (c) Alex Bilbie
@@ -7,19 +8,17 @@
78
* @link https://github.com/thephpleague/oauth2-server
89
*/
910

11+
declare(strict_types=1);
12+
1013
namespace League\OAuth2\Server\AuthorizationValidators;
1114

1215
use Psr\Http\Message\ServerRequestInterface;
1316

1417
interface AuthorizationValidatorInterface
1518
{
1619
/**
17-
* Determine the access token in the authorization header and append OAUth properties to the request
18-
* as attributes.
19-
*
20-
* @param ServerRequestInterface $request
21-
*
22-
* @return ServerRequestInterface
20+
* Determine the access token in the authorization header and append OAUth
21+
* properties to the request as attributes.
2322
*/
24-
public function validateAuthorization(ServerRequestInterface $request);
23+
public function validateAuthorization(ServerRequestInterface $request): ServerRequestInterface;
2524
}

0 commit comments

Comments
 (0)