Skip to content

Commit 6fb717e

Browse files
author
roadiz-ci
committed
chore: bumped
1 parent 345e65f commit 6fb717e

8 files changed

Lines changed: 74 additions & 41 deletions

File tree

.github/workflows/run-test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Static analysis and code style
1+
name: Unit tests, static analysis and code style
22

33
on:
44
push:
@@ -15,11 +15,11 @@ on:
1515
- ready_for_review
1616

1717
jobs:
18-
static-analysis-tests:
18+
run-tests:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
php-version: ['8.3', '8.4', '8.5']
22+
php-version: ['8.1', '8.2', '8.3']
2323
steps:
2424
- uses: shivammathur/setup-php@v2
2525
with:
@@ -35,5 +35,7 @@ jobs:
3535
${{ runner.os }}-php-${{ matrix.php-version }}-
3636
- name: Install Dependencies
3737
run: composer install --no-scripts --no-ansi --no-interaction --no-progress
38+
- name: Run PHP Code Sniffer
39+
run: vendor/bin/phpcs --extensions=php --warning-severity=0 --standard=PSR12 -p ./src
3840
- name: Run PHPStan
3941
run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2025 Ambroise Maupate
3+
Copyright © 2024 Ambroise Maupate
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
test:
3+
vendor/bin/phpcs --report=full --report-file=./report.txt -p ./src
4+
vendor/bin/phpstan analyse -c phpstan.neon

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.3",
16-
"lcobucci/jwt": "^5.3",
17-
"symfony/http-client": "7.4.*"
15+
"php": ">=8.1",
16+
"lcobucci/jwt": "^4.1",
17+
"guzzlehttp/guzzle": "^7.2.0"
1818
},
1919
"require-dev": {
20-
"phpstan/phpstan": "^2.1.36",
21-
"phpstan/phpdoc-parser": "<2"
20+
"phpstan/phpstan": "^1.5.3",
21+
"squizlabs/php_codesniffer": "^3.5"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -27,8 +27,8 @@
2727
},
2828
"extra": {
2929
"branch-alias": {
30-
"dev-main": "2.7.x-dev",
31-
"dev-develop": "2.8.x-dev"
30+
"dev-main": "2.3.x-dev",
31+
"dev-develop": "2.4.x-dev"
3232
}
3333
}
3434
}

phpcs.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg name="extensions" value="php"/>
9+
10+
<rule ref="PSR12">
11+
<exclude name="Generic.Files.LineLength"/>
12+
</rule>
13+
<file>./src</file>
14+
</ruleset>

src/JwtConfigurationFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
interface JwtConfigurationFactory
1010
{
11-
public function create(): ?Configuration;
11+
public function create(): Configuration;
1212
}

src/Validation/Constraint/HostedDomain.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@
55
namespace RZ\Roadiz\JWT\Validation\Constraint;
66

77
use Lcobucci\JWT\Token;
8-
use Lcobucci\JWT\Token\Plain;
98
use Lcobucci\JWT\Validation\Constraint;
109
use Lcobucci\JWT\Validation\ConstraintViolation;
1110

12-
final readonly class HostedDomain implements Constraint
11+
class HostedDomain implements Constraint
1312
{
14-
public function __construct(private string $hostedDomain)
13+
protected string $hostedDomain;
14+
15+
/**
16+
* @param string $hostedDomain
17+
*/
18+
public function __construct(string $hostedDomain)
1519
{
20+
$this->hostedDomain = $hostedDomain;
1621
}
1722

18-
#[\Override]
1923
public function assert(Token $token): void
2024
{
21-
if (!$token instanceof Plain || empty($this->hostedDomain)) {
22-
return;
23-
}
24-
if (!$token->claims()->has('hd')) {
25-
throw new ConstraintViolation('Token does not expose any Hosted Domain.');
26-
}
27-
/*
28-
* Check that Hosted Domain is the same as required by Roadiz
29-
*/
30-
if ($token->claims()->get('hd') !== $this->hostedDomain) {
31-
throw new ConstraintViolation('User ('.$token->claims()->get('hd').') does not belong to Hosted Domain.');
25+
if ($token instanceof Token\Plain && !empty($this->hostedDomain)) {
26+
if (!$token->claims()->has('hd')) {
27+
throw new ConstraintViolation(
28+
'Token does not expose any Hosted Domain.'
29+
);
30+
}
31+
/*
32+
* Check that Hosted Domain is the same as required by Roadiz
33+
*/
34+
if ($token->claims()->get('hd') !== $this->hostedDomain) {
35+
throw new ConstraintViolation(
36+
'User (' . $token->claims()->get('hd') . ') does not belong to Hosted Domain.'
37+
);
38+
}
3239
}
3340
}
3441
}

src/Validation/Constraint/UserInfoEndpoint.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,39 @@
44

55
namespace RZ\Roadiz\JWT\Validation\Constraint;
66

7+
use GuzzleHttp\Client;
8+
use GuzzleHttp\Exception\GuzzleException;
79
use Lcobucci\JWT\Token;
810
use Lcobucci\JWT\Validation\Constraint;
911
use Lcobucci\JWT\Validation\ConstraintViolation;
10-
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
11-
use Symfony\Contracts\HttpClient\HttpClientInterface;
1212

13-
final readonly class UserInfoEndpoint implements Constraint
13+
class UserInfoEndpoint implements Constraint
1414
{
15-
public function __construct(
16-
private string $userInfoEndpoint,
17-
private HttpClientInterface $client,
18-
) {
15+
protected string $userInfoEndpoint;
16+
17+
/**
18+
* @param string $userInfoEndpoint
19+
*/
20+
public function __construct(string $userInfoEndpoint)
21+
{
22+
$this->userInfoEndpoint = $userInfoEndpoint;
1923
}
2024

21-
#[\Override]
2225
public function assert(Token $token): void
2326
{
2427
try {
25-
$response = $this->client->request('GET', $this->userInfoEndpoint, [
28+
$client = new Client();
29+
$client->get($this->userInfoEndpoint, [
2630
'headers' => [
27-
'Authorization' => 'Bearer '.$token->toString(),
31+
'Authorization' => 'Bearer ' . $token->toString(),
2832
],
2933
]);
30-
// Trigger lazy request
31-
$response->getContent();
32-
} catch (ExceptionInterface) {
33-
throw new ConstraintViolation('Userinfo cannot be fetch from Identity provider');
34+
} catch (GuzzleException $e) {
35+
throw new ConstraintViolation(
36+
'Userinfo cannot be fetch from Identity provider',
37+
$e->getCode(),
38+
$e
39+
);
3440
}
3541
}
3642
}

0 commit comments

Comments
 (0)