Skip to content

Commit 34cd38b

Browse files
authored
Merge branch 'main' into main
2 parents 52a01fb + d598f0f commit 34cd38b

15 files changed

+99
-160
lines changed

.github/workflows/lint.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lint files
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
concurrency:
8+
group: Lint files ${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
php:
13+
name: Lint PHP files
14+
uses: monicahq/workflows/.github/workflows/lint_php.yml@v2

.github/workflows/lint_php.yml

-42
This file was deleted.

.github/workflows/static.yml

+9-68
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,13 @@ on:
44
pull_request:
55
types: [opened, synchronize, reopened]
66

7-
jobs:
8-
psalm:
9-
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
php-version: ['8.2']
13-
14-
steps:
15-
- name: Checkout sources
16-
uses: actions/checkout@v4
17-
18-
- name: Setup PHP ${{ matrix.php-version }}
19-
uses: shivammathur/setup-php@v2
20-
with:
21-
php-version: ${{ matrix.php-version }}
22-
23-
- name: Get Composer Cache Directory
24-
id: composer-cache
25-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
26-
- name: Cache composer files
27-
uses: actions/cache@v3
28-
with:
29-
path: ${{ steps.composer-cache.outputs.dir }}
30-
key: ${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}
31-
restore-keys: |
32-
${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}
33-
${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}
34-
${{ runner.os }}-composer-v4-
35-
36-
- name: Install dependencies
37-
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
38-
39-
- name: Run psalm
40-
run: vendor/bin/psalm --output-format=github
41-
7+
concurrency:
8+
group: Static ${{ github.ref }}
9+
cancel-in-progress: true
4210

43-
phpstan:
44-
runs-on: ubuntu-latest
45-
strategy:
46-
matrix:
47-
php-version: ['8.2']
48-
49-
steps:
50-
- name: Checkout sources
51-
uses: actions/checkout@v4
52-
53-
- name: Setup PHP ${{ matrix.php-version }}
54-
uses: shivammathur/setup-php@v2
55-
with:
56-
php-version: ${{ matrix.php-version }}
57-
58-
- name: Get Composer Cache Directory
59-
id: composer-cache
60-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
61-
- name: Cache composer files
62-
uses: actions/cache@v3
63-
with:
64-
path: ${{ steps.composer-cache.outputs.dir }}
65-
key: ${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}
66-
restore-keys: |
67-
${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}
68-
${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}
69-
${{ runner.os }}-composer-v4-
70-
71-
- name: Install dependencies
72-
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
73-
74-
- name : Run phpstan
75-
run: vendor/bin/phpstan analyse
11+
jobs:
12+
statics:
13+
name: Static analysis
14+
uses: monicahq/workflows/.github/workflows/static.yml@v2
15+
with:
16+
php-version: 8.2

.github/workflows/tests.yml

+27-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ on:
1919
env:
2020
default-php-version: '8.2'
2121
default-laravel-version: '10.*'
22-
semantic-node-version: 18
22+
semantic-node-version: 20
23+
24+
concurrency:
25+
group: Tests ${{ github.ref }}
26+
cancel-in-progress: true
2327

2428
jobs:
2529
tests:
@@ -29,8 +33,8 @@ jobs:
2933
strategy:
3034
fail-fast: false
3135
matrix:
32-
php-version: ['8.1','8.2']
33-
laravel-version: [9.*,10.*]
36+
php-version: ['8.1', '8.2', '8.3']
37+
laravel-version: ['9.*', '10.*']
3438
psr7: ['guzzle']
3539
include:
3640
- php-version: '8.1'
@@ -63,6 +67,8 @@ jobs:
6367
run: composer -V
6468
- name: Check PHP Extensions
6569
run: php -m
70+
- name: Setup problem matchers for PHP
71+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
6672

6773
- name: Validate composer.json
6874
run: composer validate
@@ -71,7 +77,7 @@ jobs:
7177
id: composer-cache
7278
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
7379
- name: Cache composer files
74-
uses: actions/cache@v3
80+
uses: actions/cache@v4
7581
with:
7682
path: ${{ steps.composer-cache.outputs.dir }}
7783
key: ${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}-${{ matrix.laravel-version }}
@@ -104,24 +110,25 @@ jobs:
104110
run: |
105111
composer update --no-interaction --no-progress --prefer-dist
106112
107-
- name: Setup problem matchers
108-
run: |
109-
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
110-
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
113+
- name: Set results artifact name
114+
id: artifact
115+
run: echo "name=${{ matrix.php-version }}_${{ matrix.laravel-version }}${{ matrix.psr7 }}" | sed -e "s/*//g" >> $GITHUB_OUTPUT
111116

117+
- name: Setup problem matchers
118+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
112119
- name: Run test suite
113120
run: vendor/bin/phpunit -c phpunit.xml --log-junit ./results/results_${{ matrix.psr7 }}.xml --coverage-clover ./results/coverage_${{ matrix.psr7 }}.xml
114121

115122
- name: Fix results files
123+
if: success() || failure()
116124
run: sed -i -e "s%$GITHUB_WORKSPACE/%%g" *.xml
117125
working-directory: results
118-
if: success() || failure()
119126

120127
- name: Store results
121-
if: matrix.php-version == env.default-php-version && matrix.laravel-version == env.default-laravel-version && (success() || failure())
122-
uses: actions/upload-artifact@v3
128+
if: success() || failure()
129+
uses: actions/upload-artifact@v4
123130
with:
124-
name: results
131+
name: results_${{ steps.artifact.outputs.name }}
125132
path: results
126133

127134

@@ -140,16 +147,19 @@ jobs:
140147
fetch-depth: 0
141148

142149
- name: Download results
143-
uses: actions/download-artifact@v3
150+
uses: actions/download-artifact@v4
144151
with:
145-
name: results
152+
pattern: ${{ format('results_{0}_{1}', env.default-php-version, env.default-laravel-version) }}
146153
path: results
154+
merge-multiple: true
147155

148156
- name: Merge junit files
149157
run: |
158+
mkdir -p $RUNNER_TEMP/junit-merge
159+
cd $RUNNER_TEMP/junit-merge
150160
npm init -y
151161
yarn set version berry
152-
yarn dlx junit-report-merger ./results/results.xml "./results/results*.xml"
162+
yarn dlx junit-merge --recursive --dir $GITHUB_WORKSPACE/results --out $GITHUB_WORKSPACE/results/results.xml
153163
154164
- name: Set coverage list
155165
id: coverage
@@ -159,7 +169,7 @@ jobs:
159169
160170
- name: SonarCloud Scan
161171
if: env.SONAR_TOKEN != ''
162-
uses: SonarSource/sonarcloud-github-action@v2.0.2
172+
uses: SonarSource/sonarcloud-github-action@v2
163173
env:
164174
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
165175
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -207,7 +217,7 @@ jobs:
207217

208218
- name: Store changelog file
209219
if: steps.semantic.outputs.new_release_published == 'true'
210-
uses: actions/upload-artifact@v3
220+
uses: actions/upload-artifact@v4
211221
with:
212222
name: changelog
213223
path: CHANGELOG.md

composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
"require": {
2323
"php": ">=8.1",
2424
"illuminate/support": "^9.0 || ^10.0",
25+
"phpdocumentor/reflection-docblock": "^5.3",
2526
"psr/http-factory-implementation": "1.0",
27+
"symfony/property-access": "^6.4 || ^7.0",
28+
"symfony/property-info": "^6.4 || ^7.0",
29+
"symfony/serializer": "^6.4 || ^7.0",
2630
"web-auth/cose-lib": "^4.0",
27-
"web-auth/webauthn-lib": "^4.7.1",
31+
"web-auth/webauthn-lib": "^4.8.0",
2832
"web-token/jwt-signature": "^3.0"
2933
},
3034
"conflict": {

src/Actions/AttemptToAuthenticate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function throwFailedAuthenticationException(Request $request): void
113113
/**
114114
* Fire the failed authentication attempt event with the given arguments.
115115
*/
116-
protected function fireFailedEvent(Request $request, User $user = null): void
116+
protected function fireFailedEvent(Request $request, ?User $user = null): void
117117
{
118118
event(new Failed(config('webauthn.guard'), $user, [
119119
Webauthn::username() => $user !== null

src/Actions/PrepareCreationData.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
2828
*
2929
* @throws \Illuminate\Validation\ValidationException
3030
*/
31-
protected function throwFailedRegisterException(User $user, Exception $e = null): void
31+
protected function throwFailedRegisterException(User $user, ?Exception $e = null): void
3232
{
3333
WebauthnRegisterFailed::dispatch($user, $e);
3434

src/Actions/ValidateKeyCreation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function validateAttestation(User $user, array $data, string $keyName)
4545
*
4646
* @throws \Illuminate\Validation\ValidationException
4747
*/
48-
protected function throwFailedRegisterException(User $user, Exception $e = null): void
48+
protected function throwFailedRegisterException(User $user, ?Exception $e = null): void
4949
{
5050
WebauthnRegisterFailed::dispatch($user, $e);
5151

src/Http/Middleware/WebauthnMiddleware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(
2121
/**
2222
* Handle an incoming request.
2323
*/
24-
public function handle(Request $request, Closure $next, string $guard = null): mixed
24+
public function handle(Request $request, Closure $next, ?string $guard = null): mixed
2525
{
2626
if (Webauthn::webauthnEnabled() && ! Webauthn::check()) {
2727
abort_if($this->auth->guard($guard)->guest(), 401, /** @var string $m */ $m = trans('webauthn::errors.user_unauthenticated'));

src/Models/WebauthnKey.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function publicKeyCredentialSource(): Attribute
8989
(string) $this->user_id,
9090
$this->counter
9191
),
92-
set: function (PublicKeyCredentialSource $value, array $attributes = null): array {
92+
set: function (PublicKeyCredentialSource $value, ?array $attributes = null): array {
9393
if (((string) Arr::get($attributes, 'user_id')) !== $value->userHandle) {
9494
throw new WrongUserHandleException();
9595
}

src/Services/Webauthn.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function username(): string
5050
/**
5151
* Get a completion redirect path for a specific feature.
5252
*/
53-
public static function redirects(string $redirect, string $default = null): string
53+
public static function redirects(string $redirect, ?string $default = null): string
5454
{
5555
return config('webauthn.redirects.'.$redirect) ?? $default ?? config('webauthn.home');
5656
}

src/Services/Webauthn/CredentialAssertionValidator.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
use LaravelWebauthn\Exceptions\ResponseMismatchException;
99
use LaravelWebauthn\Services\Webauthn;
1010
use ParagonIE\ConstantTime\Base64UrlSafe;
11+
use Symfony\Component\Serializer\SerializerInterface;
1112
use Webauthn\AuthenticatorAssertionResponse;
1213
use Webauthn\AuthenticatorAssertionResponseValidator;
1314
use Webauthn\PublicKeyCredential;
14-
use Webauthn\PublicKeyCredentialLoader;
1515
use Webauthn\PublicKeyCredentialRequestOptions;
1616

1717
class CredentialAssertionValidator extends CredentialValidator
1818
{
1919
public function __construct(
2020
Request $request,
2121
Cache $cache,
22-
protected PublicKeyCredentialLoader $loader,
22+
protected SerializerInterface $loader,
2323
protected AuthenticatorAssertionResponseValidator $validator
2424
) {
2525
parent::__construct($request, $cache);
@@ -33,7 +33,8 @@ public function __construct(
3333
public function __invoke(User $user, array $data): bool
3434
{
3535
// Load the data
36-
$publicKeyCredential = $this->loader->loadArray($data);
36+
$content = json_encode($data, flags: JSON_THROW_ON_ERROR);
37+
$publicKeyCredential = $this->loader->deserialize($content, PublicKeyCredential::class, 'json');
3738

3839
// Check the response against the request
3940
$this->validator->check(
@@ -53,9 +54,9 @@ public function __invoke(User $user, array $data): bool
5354
protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
5455
{
5556
try {
56-
$value = json_decode($this->cache->pull($this->cacheKey($user)), true, flags: JSON_THROW_ON_ERROR);
57+
$value = $this->cache->pull($this->cacheKey($user));
5758

58-
return PublicKeyCredentialRequestOptions::createFromArray($value);
59+
return $this->loader->deserialize($value, PublicKeyCredentialRequestOptions::class, 'json');
5960
} catch (\Exception $e) {
6061
app('webauthn.log')->debug('Webauthn publickKey deserialize error', ['exception' => $e]);
6162
abort(404);

0 commit comments

Comments
 (0)