Skip to content

Commit

Permalink
feat: Backport command for exporting node types from the database to …
Browse files Browse the repository at this point in the history
…yaml files
  • Loading branch information
roadiz-ci committed Feb 10, 2025
1 parent fc4a3ef commit f7cd3ed
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 70 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2', '8.3']
php-version: ['8.2', '8.3']
steps:
- uses: shivammathur/setup-php@v2
with:
Expand All @@ -35,7 +35,5 @@ jobs:
${{ runner.os }}-php-${{ matrix.php-version }}-
- name: Install Dependencies
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
- name: Run PHP Code Sniffer
run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon
4 changes: 0 additions & 4 deletions Makefile

This file was deleted.

12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
}
],
"require": {
"php": ">=8.1",
"lcobucci/jwt": "^4.1",
"guzzlehttp/guzzle": "^7.2.0"
"php": ">=8.2",
"lcobucci/jwt": "^5.3",
"symfony/http-client": "6.4.*"
},
"require-dev": {
"phpstan/phpstan": "^1.5.3",
"squizlabs/php_codesniffer": "^3.5"
"phpstan/phpdoc-parser": "<2"
},
"autoload": {
"psr-4": {
Expand All @@ -27,8 +27,8 @@
},
"extra": {
"branch-alias": {
"dev-main": "2.3.x-dev",
"dev-develop": "2.4.x-dev"
"dev-main": "2.4.x-dev",
"dev-develop": "2.5.x-dev"
}
}
}
14 changes: 0 additions & 14 deletions phpcs.xml.dist

This file was deleted.

2 changes: 1 addition & 1 deletion src/JwtConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

interface JwtConfigurationFactory
{
public function create(): Configuration;
public function create(): ?Configuration;
}
36 changes: 14 additions & 22 deletions src/Validation/Constraint/HostedDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +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;

class HostedDomain implements Constraint
final readonly class HostedDomain implements Constraint
{
protected string $hostedDomain;

/**
* @param string $hostedDomain
*/
public function __construct(string $hostedDomain)
public function __construct(private string $hostedDomain)
{
$this->hostedDomain = $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.');
}
}
}
33 changes: 13 additions & 20 deletions src/Validation/Constraint/UserInfoEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,32 @@

namespace RZ\Roadiz\JWT\Validation\Constraint;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Validation\Constraint;
use Lcobucci\JWT\Validation\ConstraintViolation;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class UserInfoEndpoint implements Constraint
final readonly class UserInfoEndpoint implements Constraint
{
protected string $userInfoEndpoint;

/**
* @param string $userInfoEndpoint
*/
public function __construct(string $userInfoEndpoint)
{
$this->userInfoEndpoint = $userInfoEndpoint;
public function __construct(
private string $userInfoEndpoint,
private HttpClientInterface $client,
) {
}

public function assert(Token $token): void
{
try {
$client = new Client();
$client->get($this->userInfoEndpoint, [
$response = $this->client->request('GET', $this->userInfoEndpoint, [
'headers' => [
'Authorization' => 'Bearer ' . $token->toString(),
'Authorization' => 'Bearer '.$token->toString(),
],
]);
} catch (GuzzleException $e) {
throw new ConstraintViolation(
'Userinfo cannot be fetch from Identity provider',
$e->getCode(),
$e
);
// Trigger lazy request
$response->getContent();
} catch (ExceptionInterface $e) {
throw new ConstraintViolation('Userinfo cannot be fetch from Identity provider');
}
}
}

0 comments on commit f7cd3ed

Please sign in to comment.