Skip to content

Commit

Permalink
refactor: Removed base RozierApp class when possible, added LogTrail …
Browse files Browse the repository at this point in the history
…service for publishing message in session and logger
  • Loading branch information
roadiz-ci committed Dec 3, 2024
1 parent d66210e commit af58259
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions src/Validation/Constraint/HostedDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
namespace RZ\Roadiz\JWT\Validation\Constraint;

use Lcobucci\JWT\Token;
use Lcobucci\JWT\Token\Plain;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolation;

final class HostedDomain implements Constraint
final readonly class HostedDomain implements Constraint
{
public function __construct(private readonly string $hostedDomain)
public function __construct(private string $hostedDomain)
{
}

public function assert(Token $token): void
{
if ($token instanceof Token\Plain && !empty($this->hostedDomain)) {
if (!$token->claims()->has('hd')) {
throw new ConstraintViolation('Token does not expose any Hosted Domain.');
}
/*
* Check that Hosted Domain is the same as required by Roadiz
*/
if ($token->claims()->get('hd') !== $this->hostedDomain) {
throw new ConstraintViolation('User ('.$token->claims()->get('hd').') does not belong to Hosted Domain.');
}
if (!$token instanceof Plain || empty($this->hostedDomain)) {
return;
}
if (!$token->claims()->has('hd')) {
throw new ConstraintViolation('Token does not expose any Hosted Domain.');
}
/*
* Check that Hosted Domain is the same as required by Roadiz
*/
if ($token->claims()->get('hd') !== $this->hostedDomain) {
throw new ConstraintViolation('User ('.$token->claims()->get('hd').') does not belong to Hosted Domain.');
}
}
}
6 changes: 3 additions & 3 deletions src/Validation/Constraint/UserInfoEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class UserInfoEndpoint implements Constraint
final readonly class UserInfoEndpoint implements Constraint
{
public function __construct(
private readonly string $userInfoEndpoint,
private readonly HttpClientInterface $client,
private string $userInfoEndpoint,
private HttpClientInterface $client,
) {
}

Expand Down

0 comments on commit af58259

Please sign in to comment.