@@ -120,7 +120,7 @@ |
||
| 120 | 120 | */ |
| 121 | 121 | protected function shouldBeProcessed(ServerRequestInterface $request): bool |
| 122 | 122 | {
|
| 123 | - //If no route has been match no need check |
|
| 123 | + //If no route has been match no need check |
|
| 124 | 124 | /** @var Route|null $route */ |
| 125 | 125 | $route = $request->getAttribute(Route::class); |
| 126 | 126 | if ($route === null) {
|
@@ -49,8 +49,7 @@ discard block |
||
| 49 | 49 | * @package Platine\Framework\OAuth2\Middleware |
| 50 | 50 | * @template T |
| 51 | 51 | */ |
| 52 | -class OauthResourceMiddleware implements MiddlewareInterface |
|
| 53 | -{
|
|
| 52 | +class OauthResourceMiddleware implements MiddlewareInterface { |
|
| 54 | 53 | /** |
| 55 | 54 | * The Resource Server |
| 56 | 55 | * @var ResourceServerInterface |
@@ -77,7 +76,7 @@ discard block |
||
| 77 | 76 | public function __construct( |
| 78 | 77 | ResourceServerInterface $resourceServer, |
| 79 | 78 | Config $config |
| 80 | - ) {
|
|
| 79 | + ) { |
|
| 81 | 80 | $this->resourceServer = $resourceServer; |
| 82 | 81 | $this->config = $config; |
| 83 | 82 | } |
@@ -89,16 +88,16 @@ discard block |
||
| 89 | 88 | ServerRequestInterface $request, |
| 90 | 89 | RequestHandlerInterface $handler |
| 91 | 90 | ): ResponseInterface {
|
| 92 | - if ($this->shouldBeProcessed($request) === false) {
|
|
| 91 | + if ($this->shouldBeProcessed($request) === false) { |
|
| 93 | 92 | return $handler->handle($request); |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | - try {
|
|
| 95 | + try { |
|
| 97 | 96 | $token = $this->resourceServer->getAccessToken($request, $this->scopes); |
| 98 | - if ($token === null) {
|
|
| 97 | + if ($token === null) { |
|
| 99 | 98 | throw InvalidAccessTokenException::invalidToken('No access token found in the request');
|
| 100 | 99 | } |
| 101 | - } catch (InvalidAccessTokenException $ex) {
|
|
| 100 | + } catch (InvalidAccessTokenException $ex) { |
|
| 102 | 101 | // If we're here, this means that there was an access token, but it's either expired |
| 103 | 102 | // or invalid. If that's the case we must immediately return |
| 104 | 103 | return new JsonResponse( |
@@ -123,7 +122,7 @@ discard block |
||
| 123 | 122 | //If no route has been match no need check |
| 124 | 123 | /** @var Route|null $route */ |
| 125 | 124 | $route = $request->getAttribute(Route::class); |
| 126 | - if ($route === null) {
|
|
| 125 | + if ($route === null) { |
|
| 127 | 126 | return false; |
| 128 | 127 | } |
| 129 | 128 | |
@@ -132,7 +131,7 @@ discard block |
||
| 132 | 131 | |
| 133 | 132 | //check if is url whitelist |
| 134 | 133 | $urls = $this->config->get('oauth2.url_whitelist', []);
|
| 135 | - if (in_array($route->getName(), $urls)) {
|
|
| 134 | + if (in_array($route->getName(), $urls)) { |
|
| 136 | 135 | return false; |
| 137 | 136 | } |
| 138 | 137 | |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | * @class AuthorizationRequestHandler |
| 44 | 44 | * @package Platine\Framework\OAuth2\Handler |
| 45 | 45 | */ |
| 46 | -class AuthorizationRequestHandler implements RequestHandlerInterface |
|
| 47 | -{
|
|
| 46 | +class AuthorizationRequestHandler implements RequestHandlerInterface { |
|
| 48 | 47 | /** |
| 49 | 48 | * The Authorization Server |
| 50 | 49 | * @var AuthorizationServerInterface |
@@ -55,8 +54,7 @@ discard block |
||
| 55 | 54 | * Create new instance |
| 56 | 55 | * @param AuthorizationServerInterface $authorizationServer |
| 57 | 56 | */ |
| 58 | - public function __construct(AuthorizationServerInterface $authorizationServer) |
|
| 59 | - {
|
|
| 57 | + public function __construct(AuthorizationServerInterface $authorizationServer) { |
|
| 60 | 58 | $this->authorizationServer = $authorizationServer; |
| 61 | 59 | } |
| 62 | 60 | |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | * @class AccessTokenRequestHandler |
| 44 | 44 | * @package Platine\Framework\OAuth2\Handler |
| 45 | 45 | */ |
| 46 | -class AccessTokenRequestHandler implements RequestHandlerInterface |
|
| 47 | -{
|
|
| 46 | +class AccessTokenRequestHandler implements RequestHandlerInterface { |
|
| 48 | 47 | /** |
| 49 | 48 | * The Authorization Server |
| 50 | 49 | * @var AuthorizationServerInterface |
@@ -55,8 +54,7 @@ discard block |
||
| 55 | 54 | * Create new instance |
| 56 | 55 | * @param AuthorizationServerInterface $authorizationServer |
| 57 | 56 | */ |
| 58 | - public function __construct(AuthorizationServerInterface $authorizationServer) |
|
| 59 | - {
|
|
| 57 | + public function __construct(AuthorizationServerInterface $authorizationServer) { |
|
| 60 | 58 | $this->authorizationServer = $authorizationServer; |
| 61 | 59 | } |
| 62 | 60 | |
@@ -42,8 +42,7 @@ discard block |
||
| 42 | 42 | * @class TokenRevocationRequestHandler |
| 43 | 43 | * @package Platine\Framework\OAuth2\Handler |
| 44 | 44 | */ |
| 45 | -class TokenRevocationRequestHandler implements RequestHandlerInterface |
|
| 46 | -{
|
|
| 45 | +class TokenRevocationRequestHandler implements RequestHandlerInterface { |
|
| 47 | 46 | /** |
| 48 | 47 | * The Authorization Server |
| 49 | 48 | * @var AuthorizationServerInterface |
@@ -54,8 +53,7 @@ discard block |
||
| 54 | 53 | * Create new instance |
| 55 | 54 | * @param AuthorizationServerInterface $authorizationServer |
| 56 | 55 | */ |
| 57 | - public function __construct(AuthorizationServerInterface $authorizationServer) |
|
| 58 | - {
|
|
| 56 | + public function __construct(AuthorizationServerInterface $authorizationServer) { |
|
| 59 | 57 | $this->authorizationServer = $authorizationServer; |
| 60 | 58 | } |
| 61 | 59 | |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | $this->clientService = $clientService; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * {@inheritdoc}
|
|
| 85 | - */ |
|
| 83 | + /** |
|
| 84 | + * {@inheritdoc}
|
|
| 85 | + */ |
|
| 86 | 86 | public function cleanExpiredTokens(): void |
| 87 | 87 | {
|
| 88 | 88 | $this->query()->where('expires')->lte(date('Y-m-d H:i:s'))
|
| 89 | - ->delete(); |
|
| 89 | + ->delete(); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * {@inheritdoc}
|
|
| 94 | - */ |
|
| 92 | + /** |
|
| 93 | + * {@inheritdoc}
|
|
| 94 | + */ |
|
| 95 | 95 | public function deleteToken(BaseToken $token): bool |
| 96 | 96 | {
|
| 97 | 97 | return $this->query()->where('refresh_token')->is($token->getToken())
|
| 98 | - ->delete() >= 0; |
|
| 98 | + ->delete() >= 0; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * {@inheritdoc}
|
|
| 103 | - */ |
|
| 101 | + /** |
|
| 102 | + * {@inheritdoc}
|
|
| 103 | + */ |
|
| 104 | 104 | public function getByToken(string $token): ?BaseToken |
| 105 | 105 | {
|
| 106 | 106 | $refreshToken = $this->find($token); |
@@ -122,17 +122,17 @@ discard block |
||
| 122 | 122 | ]); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * {@inheritdoc}
|
|
| 127 | - */ |
|
| 125 | + /** |
|
| 126 | + * {@inheritdoc}
|
|
| 127 | + */ |
|
| 128 | 128 | public function isTokenExists(string $token): bool |
| 129 | 129 | {
|
| 130 | 130 | return $this->find($token) !== null; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * {@inheritdoc}
|
|
| 135 | - */ |
|
| 133 | + /** |
|
| 134 | + * {@inheritdoc}
|
|
| 135 | + */ |
|
| 136 | 136 | public function saveRefreshToken(RefreshToken $token): RefreshToken |
| 137 | 137 | {
|
| 138 | 138 | $clientId = null; |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | * @package Platine\Framework\OAuth2\Repository |
| 62 | 62 | * @extends Repository<OauthRefreshToken> |
| 63 | 63 | */ |
| 64 | -class RefreshTokenRepository extends Repository implements RefreshTokenRepositoryInterface |
|
| 65 | -{
|
|
| 64 | +class RefreshTokenRepository extends Repository implements RefreshTokenRepositoryInterface { |
|
| 66 | 65 | /** |
| 67 | 66 | * The Client Service |
| 68 | 67 | * @var ClientService |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | * @param EntityManager<OauthRefreshToken> $manager |
| 75 | 74 | * @param ClientService $clientService |
| 76 | 75 | */ |
| 77 | - public function __construct(EntityManager $manager, ClientService $clientService) |
|
| 78 | - {
|
|
| 76 | + public function __construct(EntityManager $manager, ClientService $clientService) { |
|
| 79 | 77 | parent::__construct($manager, OauthRefreshToken::class); |
| 80 | 78 | $this->clientService = $clientService; |
| 81 | 79 | } |
@@ -104,12 +102,12 @@ discard block |
||
| 104 | 102 | public function getByToken(string $token): ?BaseToken |
| 105 | 103 | {
|
| 106 | 104 | $refreshToken = $this->find($token); |
| 107 | - if ($refreshToken === null) {
|
|
| 105 | + if ($refreshToken === null) { |
|
| 108 | 106 | return null; |
| 109 | 107 | } |
| 110 | 108 | |
| 111 | 109 | $client = null; |
| 112 | - if ($refreshToken->client_id !== null) {
|
|
| 110 | + if ($refreshToken->client_id !== null) { |
|
| 113 | 111 | $client = $this->clientService->find($refreshToken->client_id); |
| 114 | 112 | } |
| 115 | 113 | |
@@ -136,12 +134,12 @@ discard block |
||
| 136 | 134 | public function saveRefreshToken(RefreshToken $token): RefreshToken |
| 137 | 135 | {
|
| 138 | 136 | $clientId = null; |
| 139 | - if ($token->getClient() !== null) {
|
|
| 137 | + if ($token->getClient() !== null) { |
|
| 140 | 138 | $clientId = $token->getClient()->getId(); |
| 141 | 139 | } |
| 142 | 140 | |
| 143 | 141 | $ownerId = null; |
| 144 | - if ($token->getOwner() !== null) {
|
|
| 142 | + if ($token->getOwner() !== null) { |
|
| 145 | 143 | $ownerId = $token->getOwner()->getOwnerId(); |
| 146 | 144 | } |
| 147 | 145 | |
@@ -58,14 +58,12 @@ discard block |
||
| 58 | 58 | * @package Platine\Framework\OAuth2\Repository |
| 59 | 59 | * @extends Repository<OauthClient> |
| 60 | 60 | */ |
| 61 | -class ClientRepository extends Repository implements ClientRepositoryInterface |
|
| 62 | -{
|
|
| 61 | +class ClientRepository extends Repository implements ClientRepositoryInterface { |
|
| 63 | 62 | /** |
| 64 | 63 | * Create new instance |
| 65 | 64 | * @param EntityManager<OauthClient> $manager |
| 66 | 65 | */ |
| 67 | - public function __construct(EntityManager $manager) |
|
| 68 | - {
|
|
| 66 | + public function __construct(EntityManager $manager) { |
|
| 69 | 67 | parent::__construct($manager, OauthClient::class); |
| 70 | 68 | } |
| 71 | 69 | |
@@ -83,7 +81,7 @@ discard block |
||
| 83 | 81 | public function findClient(string $id): ?Client |
| 84 | 82 | {
|
| 85 | 83 | $client = $this->find($id); |
| 86 | - if ($client === null) {
|
|
| 84 | + if ($client === null) { |
|
| 87 | 85 | return null; |
| 88 | 86 | } |
| 89 | 87 | return Client::hydrate([ |
@@ -93,8 +93,8 @@ |
||
| 93 | 93 | public function getDefaultScopes(): array |
| 94 | 94 | {
|
| 95 | 95 | $result = $this->query() |
| 96 | - ->where('is_default')->is(1)
|
|
| 97 | - ->all(); |
|
| 96 | + ->where('is_default')->is(1)
|
|
| 97 | + ->all(); |
|
| 98 | 98 | $scopes = []; |
| 99 | 99 | foreach ($result as $row) {
|
| 100 | 100 | $scopes[] = Scope::createNewScope( |
@@ -58,14 +58,12 @@ discard block |
||
| 58 | 58 | * @package Platine\Framework\OAuth2\Repository |
| 59 | 59 | * @extends Repository<OauthScope> |
| 60 | 60 | */ |
| 61 | -class ScopeRepository extends Repository implements ScopeRepositoryInterface |
|
| 62 | -{
|
|
| 61 | +class ScopeRepository extends Repository implements ScopeRepositoryInterface { |
|
| 63 | 62 | /** |
| 64 | 63 | * Create new instance |
| 65 | 64 | * @param EntityManager<OauthScope> $manager |
| 66 | 65 | */ |
| 67 | - public function __construct(EntityManager $manager) |
|
| 68 | - {
|
|
| 66 | + public function __construct(EntityManager $manager) { |
|
| 69 | 67 | parent::__construct($manager, OauthScope::class); |
| 70 | 68 | } |
| 71 | 69 | |
@@ -76,7 +74,7 @@ discard block |
||
| 76 | 74 | {
|
| 77 | 75 | $result = $this->all(); |
| 78 | 76 | $scopes = []; |
| 79 | - foreach ($result as $row) {
|
|
| 77 | + foreach ($result as $row) { |
|
| 80 | 78 | $scopes[] = Scope::createNewScope( |
| 81 | 79 | $row->id, |
| 82 | 80 | $row->name, |
@@ -96,7 +94,7 @@ discard block |
||
| 96 | 94 | ->where('is_default')->is(1)
|
| 97 | 95 | ->all(); |
| 98 | 96 | $scopes = []; |
| 99 | - foreach ($result as $row) {
|
|
| 97 | + foreach ($result as $row) { |
|
| 100 | 98 | $scopes[] = Scope::createNewScope( |
| 101 | 99 | $row->id, |
| 102 | 100 | $row->name, |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function cleanExpiredTokens(): void |
| 87 | 87 | {
|
| 88 | 88 | $this->query()->where('expires')->lte(date('Y-m-d H:i:s'))
|
| 89 | - ->delete(); |
|
| 89 | + ->delete(); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function deleteToken(BaseToken $token): bool |
| 96 | 96 | {
|
| 97 | 97 | return $this->query()->where('authorization_code')->is($token->getToken())
|
| 98 | - ->delete() >= 0; |
|
| 98 | + ->delete() >= 0; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | * @package Platine\Framework\OAuth2\Repository |
| 62 | 62 | * @extends Repository<OauthAuthorizationCode> |
| 63 | 63 | */ |
| 64 | -class AuthorizationCodeRepository extends Repository implements AuthorizationCodeRepositoryInterface |
|
| 65 | -{
|
|
| 64 | +class AuthorizationCodeRepository extends Repository implements AuthorizationCodeRepositoryInterface { |
|
| 66 | 65 | /** |
| 67 | 66 | * The Client Service |
| 68 | 67 | * @var ClientService |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | * @param EntityManager<OauthAuthorizationCode> $manager |
| 75 | 74 | * @param ClientService $clientService |
| 76 | 75 | */ |
| 77 | - public function __construct(EntityManager $manager, ClientService $clientService) |
|
| 78 | - {
|
|
| 76 | + public function __construct(EntityManager $manager, ClientService $clientService) { |
|
| 79 | 77 | parent::__construct($manager, OauthAuthorizationCode::class); |
| 80 | 78 | $this->clientService = $clientService; |
| 81 | 79 | } |
@@ -104,12 +102,12 @@ discard block |
||
| 104 | 102 | public function getByToken(string $token): ?BaseToken |
| 105 | 103 | {
|
| 106 | 104 | $code = $this->find($token); |
| 107 | - if ($code === null) {
|
|
| 105 | + if ($code === null) { |
|
| 108 | 106 | return null; |
| 109 | 107 | } |
| 110 | 108 | |
| 111 | 109 | $client = null; |
| 112 | - if ($code->client_id !== null) {
|
|
| 110 | + if ($code->client_id !== null) { |
|
| 113 | 111 | $client = $this->clientService->find($code->client_id); |
| 114 | 112 | } |
| 115 | 113 | |
@@ -137,12 +135,12 @@ discard block |
||
| 137 | 135 | public function saveCode(AuthorizationCode $token): AuthorizationCode |
| 138 | 136 | {
|
| 139 | 137 | $clientId = null; |
| 140 | - if ($token->getClient() !== null) {
|
|
| 138 | + if ($token->getClient() !== null) { |
|
| 141 | 139 | $clientId = $token->getClient()->getId(); |
| 142 | 140 | } |
| 143 | 141 | |
| 144 | 142 | $ownerId = null; |
| 145 | - if ($token->getOwner() !== null) {
|
|
| 143 | + if ($token->getOwner() !== null) { |
|
| 146 | 144 | $ownerId = $token->getOwner()->getOwnerId(); |
| 147 | 145 | } |
| 148 | 146 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | public function cleanExpiredTokens(): void |
| 87 | 87 | {
|
| 88 | 88 | $this->query()->where('expires')->lte(date('Y-m-d H:i:s'))
|
| 89 | - ->delete(); |
|
| 89 | + ->delete(); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function deleteToken(BaseToken $token): bool |
| 96 | 96 | {
|
| 97 | 97 | return $this->query()->where('access_token')->is($token->getToken())
|
| 98 | - ->delete() >= 0; |
|
| 98 | + ->delete() >= 0; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | * @package Platine\Framework\OAuth2\Repository |
| 62 | 62 | * @extends Repository<OauthAccessToken> |
| 63 | 63 | */ |
| 64 | -class AccessTokenRepository extends Repository implements AccessTokenRepositoryInterface |
|
| 65 | -{
|
|
| 64 | +class AccessTokenRepository extends Repository implements AccessTokenRepositoryInterface { |
|
| 66 | 65 | /** |
| 67 | 66 | * The Client Service |
| 68 | 67 | * @var ClientService |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | * @param EntityManager<OauthAccessToken> $manager |
| 75 | 74 | * @param ClientService $clientService |
| 76 | 75 | */ |
| 77 | - public function __construct(EntityManager $manager, ClientService $clientService) |
|
| 78 | - {
|
|
| 76 | + public function __construct(EntityManager $manager, ClientService $clientService) { |
|
| 79 | 77 | parent::__construct($manager, OauthAccessToken::class); |
| 80 | 78 | $this->clientService = $clientService; |
| 81 | 79 | } |
@@ -104,12 +102,12 @@ discard block |
||
| 104 | 102 | public function getByToken(string $token): ?BaseToken |
| 105 | 103 | {
|
| 106 | 104 | $accessToken = $this->find($token); |
| 107 | - if ($accessToken === null) {
|
|
| 105 | + if ($accessToken === null) { |
|
| 108 | 106 | return null; |
| 109 | 107 | } |
| 110 | 108 | |
| 111 | 109 | $client = null; |
| 112 | - if ($accessToken->client_id !== null) {
|
|
| 110 | + if ($accessToken->client_id !== null) { |
|
| 113 | 111 | $client = $this->clientService->find($accessToken->client_id); |
| 114 | 112 | } |
| 115 | 113 | |
@@ -136,12 +134,12 @@ discard block |
||
| 136 | 134 | public function saveAccessToken(AccessToken $token): AccessToken |
| 137 | 135 | {
|
| 138 | 136 | $clientId = null; |
| 139 | - if ($token->getClient() !== null) {
|
|
| 137 | + if ($token->getClient() !== null) { |
|
| 140 | 138 | $clientId = $token->getClient()->getId(); |
| 141 | 139 | } |
| 142 | 140 | |
| 143 | 141 | $ownerId = null; |
| 144 | - if ($token->getOwner() !== null) {
|
|
| 142 | + if ($token->getOwner() !== null) { |
|
| 145 | 143 | $ownerId = $token->getOwner()->getOwnerId(); |
| 146 | 144 | } |
| 147 | 145 | |