-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1375 from Sephster/php-8-1-compat
Add Types to the Library
- Loading branch information
Showing
88 changed files
with
2,092 additions
and
2,621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
parameters: | ||
level: 8 | ||
paths: | ||
- src | ||
- tests | ||
ignoreErrors: | ||
- | ||
message: '#Call to an undefined method League\\OAuth2\\Server\\ResponseTypes\\ResponseTypeInterface::getAccessToken\(\)\.#' | ||
path: tests/Grant/ClientCredentialsGrantTest.php | ||
- '#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\(\)#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
|
@@ -7,6 +8,8 @@ | |
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OAuth2\Server; | ||
|
||
use DateInterval; | ||
|
@@ -32,79 +35,36 @@ class AuthorizationServer implements EmitterAwareInterface | |
/** | ||
* @var GrantTypeInterface[] | ||
*/ | ||
protected $enabledGrantTypes = []; | ||
protected array $enabledGrantTypes = []; | ||
|
||
/** | ||
* @var DateInterval[] | ||
*/ | ||
protected $grantTypeAccessTokenTTL = []; | ||
protected array $grantTypeAccessTokenTTL = []; | ||
|
||
/** | ||
* @var CryptKeyInterface | ||
*/ | ||
protected $privateKey; | ||
protected CryptKeyInterface $privateKey; | ||
|
||
/** | ||
* @var CryptKeyInterface | ||
*/ | ||
protected $publicKey; | ||
protected CryptKeyInterface $publicKey; | ||
|
||
/** | ||
* @var ResponseTypeInterface | ||
*/ | ||
protected $responseType; | ||
protected ResponseTypeInterface $responseType; | ||
|
||
/** | ||
* @var ClientRepositoryInterface | ||
*/ | ||
private $clientRepository; | ||
private string|Key $encryptionKey; | ||
|
||
/** | ||
* @var AccessTokenRepositoryInterface | ||
*/ | ||
private $accessTokenRepository; | ||
private string $defaultScope = ''; | ||
|
||
/** | ||
* @var ScopeRepositoryInterface | ||
*/ | ||
private $scopeRepository; | ||
private bool $revokeRefreshTokens = true; | ||
|
||
/** | ||
* @var string|Key | ||
*/ | ||
private $encryptionKey; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $defaultScope = ''; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $revokeRefreshTokens = true; | ||
|
||
/** | ||
* New server instance. | ||
* | ||
* @param ClientRepositoryInterface $clientRepository | ||
* @param AccessTokenRepositoryInterface $accessTokenRepository | ||
* @param ScopeRepositoryInterface $scopeRepository | ||
* @param CryptKeyInterface|string $privateKey | ||
* @param string|Key $encryptionKey | ||
* @param null|ResponseTypeInterface $responseType | ||
* New server instance | ||
*/ | ||
public function __construct( | ||
ClientRepositoryInterface $clientRepository, | ||
AccessTokenRepositoryInterface $accessTokenRepository, | ||
ScopeRepositoryInterface $scopeRepository, | ||
$privateKey, | ||
$encryptionKey, | ||
ResponseTypeInterface $responseType = null | ||
private ClientRepositoryInterface $clientRepository, | ||
private AccessTokenRepositoryInterface $accessTokenRepository, | ||
private ScopeRepositoryInterface $scopeRepository, | ||
CryptKeyInterface|string $privateKey, | ||
Key|string $encryptionKey, | ||
ResponseTypeInterface|null $responseType = null | ||
) { | ||
$this->clientRepository = $clientRepository; | ||
$this->accessTokenRepository = $accessTokenRepository; | ||
$this->scopeRepository = $scopeRepository; | ||
|
||
if ($privateKey instanceof CryptKeyInterface === false) { | ||
$privateKey = new CryptKey($privateKey); | ||
|
@@ -123,12 +83,9 @@ public function __construct( | |
} | ||
|
||
/** | ||
* Enable a grant type on the server. | ||
* | ||
* @param GrantTypeInterface $grantType | ||
* @param null|DateInterval $accessTokenTTL | ||
* Enable a grant type on the server | ||
*/ | ||
public function enableGrantType(GrantTypeInterface $grantType, DateInterval $accessTokenTTL = null) | ||
public function enableGrantType(GrantTypeInterface $grantType, DateInterval|null $accessTokenTTL = null): void | ||
{ | ||
if ($accessTokenTTL === null) { | ||
$accessTokenTTL = new DateInterval('PT1H'); | ||
|
@@ -150,13 +107,9 @@ public function enableGrantType(GrantTypeInterface $grantType, DateInterval $acc | |
/** | ||
* Validate an authorization request | ||
* | ||
* @param ServerRequestInterface $request | ||
* | ||
* @throws OAuthServerException | ||
* | ||
* @return AuthorizationRequestInterface | ||
*/ | ||
public function validateAuthorizationRequest(ServerRequestInterface $request) | ||
public function validateAuthorizationRequest(ServerRequestInterface $request): AuthorizationRequestInterface | ||
{ | ||
foreach ($this->enabledGrantTypes as $grantType) { | ||
if ($grantType->canRespondToAuthorizationRequest($request)) { | ||
|
@@ -169,16 +122,11 @@ public function validateAuthorizationRequest(ServerRequestInterface $request) | |
|
||
/** | ||
* Complete an authorization request | ||
* | ||
* @param AuthorizationRequestInterface $authRequest | ||
* @param ResponseInterface $response | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function completeAuthorizationRequest( | ||
AuthorizationRequestInterface $authRequest, | ||
ResponseInterface $response | ||
) { | ||
): ResponseInterface { | ||
return $this->enabledGrantTypes[$authRequest->getGrantTypeId()] | ||
->completeAuthorizationRequest($authRequest) | ||
->generateHttpResponse($response); | ||
|
@@ -187,39 +135,31 @@ public function completeAuthorizationRequest( | |
/** | ||
* Return an access token response. | ||
* | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
* | ||
* @throws OAuthServerException | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response) | ||
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface | ||
{ | ||
foreach ($this->enabledGrantTypes as $grantType) { | ||
if (!$grantType->canRespondToAccessTokenRequest($request)) { | ||
continue; | ||
} | ||
|
||
$tokenResponse = $grantType->respondToAccessTokenRequest( | ||
$request, | ||
$this->getResponseType(), | ||
$this->grantTypeAccessTokenTTL[$grantType->getIdentifier()] | ||
); | ||
|
||
if ($tokenResponse instanceof ResponseTypeInterface) { | ||
return $tokenResponse->generateHttpResponse($response); | ||
} | ||
return $tokenResponse->generateHttpResponse($response); | ||
} | ||
|
||
throw OAuthServerException::unsupportedGrantType(); | ||
} | ||
|
||
/** | ||
* Get the token type that grants will return in the HTTP response. | ||
* | ||
* @return ResponseTypeInterface | ||
*/ | ||
protected function getResponseType() | ||
protected function getResponseType(): ResponseTypeInterface | ||
{ | ||
$responseType = clone $this->responseType; | ||
|
||
|
@@ -234,18 +174,14 @@ protected function getResponseType() | |
|
||
/** | ||
* Set the default scope for the authorization server. | ||
* | ||
* @param string $defaultScope | ||
*/ | ||
public function setDefaultScope($defaultScope) | ||
public function setDefaultScope(string $defaultScope): void | ||
{ | ||
$this->defaultScope = $defaultScope; | ||
} | ||
|
||
/** | ||
* Sets whether to revoke refresh tokens or not (for all grant types). | ||
* | ||
* @param bool $revokeRefreshTokens | ||
*/ | ||
public function revokeRefreshTokens(bool $revokeRefreshTokens): void | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
|
@@ -7,19 +8,17 @@ | |
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\OAuth2\Server\AuthorizationValidators; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
interface AuthorizationValidatorInterface | ||
{ | ||
/** | ||
* Determine the access token in the authorization header and append OAUth properties to the request | ||
* as attributes. | ||
* | ||
* @param ServerRequestInterface $request | ||
* | ||
* @return ServerRequestInterface | ||
* Determine the access token in the authorization header and append OAUth | ||
* properties to the request as attributes. | ||
*/ | ||
public function validateAuthorization(ServerRequestInterface $request); | ||
public function validateAuthorization(ServerRequestInterface $request): ServerRequestInterface; | ||
} |
Oops, something went wrong.