Skip to content

Commit

Permalink
fix backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Feb 6, 2025
1 parent f51da5f commit f342bd8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ext-openssl": "*",
"league/event": "^3.0",
"league/uri": "^7.0",
"lcobucci/jwt": "^5.5",
"lcobucci/jwt": "^5.0",
"psr/http-message": "^2.0",
"defuse/php-encryption": "^2.4",
"ext-json": "*",
Expand Down
19 changes: 14 additions & 5 deletions src/AuthorizationValidators/BearerTokenValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function setPublicKey(CryptKeyInterface $key): void
*/
private function initJwtConfiguration(): void
{
$this->jwtConfiguration = Configuration::forSymmetricSigner(
new Sha256(),
InMemory::plainText('empty', 'empty')
);

$clock = new SystemClock(new DateTimeZone(date_default_timezone_get()));

$publicKeyContents = $this->publicKey->getKeyContents();
Expand All @@ -69,16 +74,20 @@ private function initJwtConfiguration(): void
throw new RuntimeException('Public key is empty');
}

$this->jwtConfiguration = Configuration::forSymmetricSigner(
new Sha256(),
InMemory::plainText('empty', 'empty')
)->withValidationConstraints(
$validationConstraints = [
new LooseValidAt($clock, $this->jwtValidAtDateLeeway),
new SignedWith(
new Sha256(),
InMemory::plainText($publicKeyContents, $this->publicKey->getPassPhrase() ?? '')
)
);
];

// TODO: next major release: remove this check
if (method_exists($this->jwtConfiguration, 'withValidationConstraints') === true) {

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.1, prefer-lowest, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to false.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.1, prefer-stable, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to false.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.2, prefer-lowest, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to false.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.2, prefer-stable, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to true.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.3, prefer-lowest, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to false.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.3, prefer-stable, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to true.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.4, prefer-lowest, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to false.

Check failure on line 86 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.4, prefer-stable, ubuntu-latest)

Call to function method_exists() with Lcobucci\JWT\Configuration and 'withValidationConst…' will always evaluate to true.
$this->jwtConfiguration = $this->jwtConfiguration->withValidationConstraints(...$validationConstraints);
} else {
$this->jwtConfiguration->setValidationConstraints(...$validationConstraints);

Check failure on line 89 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.2, prefer-stable, ubuntu-latest)

Call to deprecated method setValidationConstraints() of class Lcobucci\JWT\Configuration: Deprecated since v5.5, please use {@see self::withValidationConstraints()} instead

Check failure on line 89 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.3, prefer-stable, ubuntu-latest)

Call to deprecated method setValidationConstraints() of class Lcobucci\JWT\Configuration: Deprecated since v5.5, please use {@see self::withValidationConstraints()} instead

Check failure on line 89 in src/AuthorizationValidators/BearerTokenValidator.php

View workflow job for this annotation

GitHub Actions / Static Analysis (8.4, prefer-stable, ubuntu-latest)

Call to deprecated method setValidationConstraints() of class Lcobucci\JWT\Configuration: Deprecated since v5.5, please use {@see self::withValidationConstraints()} instead
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/ClientEntityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function isConfidential(): bool;
/*
* Returns true if the client supports the given grant type.
*
* To be added in a future major release.
* TODO: To be added in a future major release.
*/
// public function supportsGrantType(string $grantType): bool;
}

0 comments on commit f342bd8

Please sign in to comment.