Skip to content

Commit bf6c54a

Browse files
authored
feat: Add support to Laravel 9.x, and remove Laravel 7.x and 8.x (#377)
1 parent af83780 commit bf6c54a

21 files changed

+206
-125
lines changed

.github/workflows/static.yml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ on:
55
types: [opened, synchronize, reopened]
66

77
jobs:
8-
psalm:
9-
runs-on: ubuntu-latest
10-
strategy:
11-
matrix:
12-
php-version: ['8.1']
8+
# psalm:
9+
# runs-on: ubuntu-latest
10+
# strategy:
11+
# matrix:
12+
# php-version: ['8.1']
1313

14-
steps:
15-
- name: Checkout sources
16-
uses: actions/checkout@v3
14+
# steps:
15+
# - name: Checkout sources
16+
# uses: actions/checkout@v3
1717

18-
- name: Setup PHP ${{ matrix.php-version }}
19-
uses: shivammathur/setup-php@v2
20-
with:
21-
php-version: ${{ matrix.php-version }}
18+
# - name: Setup PHP ${{ matrix.php-version }}
19+
# uses: shivammathur/setup-php@v2
20+
# with:
21+
# php-version: ${{ matrix.php-version }}
2222

23-
- name: Get Composer Cache Directory
24-
id: composer-cache
25-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
26-
- name: Cache composer files
27-
uses: actions/cache@v2.1.7
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-
23+
# - name: Get Composer Cache Directory
24+
# id: composer-cache
25+
# run: echo "::set-output name=dir::$(composer config cache-files-dir)"
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-
3535

36-
- name: Install dependencies
37-
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
36+
# - name: Install dependencies
37+
# run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
3838

39-
- name: Run psalm
40-
run: vendor/bin/psalm --output-format=github
39+
# - name: Run psalm
40+
# run: vendor/bin/psalm --output-format=github
4141

4242

4343
phpstan:
@@ -59,7 +59,7 @@ jobs:
5959
id: composer-cache
6060
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
6161
- name: Cache composer files
62-
uses: actions/cache@v2.1.7
62+
uses: actions/cache@v3
6363
with:
6464
path: ${{ steps.composer-cache.outputs.dir }}
6565
key: ${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}

.github/workflows/tests.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717

1818
env:
1919
default-php-version: '8.1'
20-
default-laravel-version: '8.*'
20+
default-laravel-version: '9.*'
2121
semantic-node-version: 16
2222

2323
jobs:
@@ -29,14 +29,14 @@ jobs:
2929
fail-fast: false
3030
matrix:
3131
php-version: ['8.1']
32-
laravel-version: [8.*]
32+
laravel-version: [9.*]
3333
psr7: ['guzzle']
3434
include:
3535
- php-version: '8.1'
36-
laravel-version: '8.*'
36+
laravel-version: '9.*'
3737
psr7: 'nyholm'
3838
- php-version: '8.1'
39-
laravel-version: '8.*'
39+
laravel-version: '9.*'
4040
psr7: 'discovery'
4141

4242
steps:
@@ -63,7 +63,7 @@ jobs:
6363
id: composer-cache
6464
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
6565
- name: Cache composer files
66-
uses: actions/cache@v2.1.7
66+
uses: actions/cache@v3
6767
with:
6868
path: ${{ steps.composer-cache.outputs.dir }}
6969
key: ${{ runner.os }}-composer-v4-${{ hashFiles('**/composer.json') }}-${{ matrix.php-version }}-${{ matrix.laravel-version }}
@@ -105,7 +105,7 @@ jobs:
105105

106106
- name: Store results
107107
if: matrix.php-version == env.default-php-version && matrix.laravel-version == env.default-laravel-version
108-
uses: actions/upload-artifact@v2
108+
uses: actions/upload-artifact@v3
109109
with:
110110
name: results
111111
path: results
@@ -128,7 +128,7 @@ jobs:
128128
fetch-depth: 0
129129

130130
- name: Download results
131-
uses: actions/download-artifact@v2
131+
uses: actions/download-artifact@v3
132132
with:
133133
name: results
134134
path: results
@@ -189,7 +189,7 @@ jobs:
189189

190190
- name: Store changelog file
191191
if: steps.semantic.outputs.new_release_published == 'true'
192-
uses: actions/upload-artifact@v2
192+
uses: actions/upload-artifact@v3
193193
with:
194194
name: changelog
195195
path: CHANGELOG.md

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ This package has the following Laravel compatibility:
435435
| Laravel | [asbiin/laravel-webauthn](https://github.com/asbiin/laravel-webauthn) |
436436
|----------|----------|
437437
| 5.8-8.x | <= 1.2.0 |
438-
| 7.x-8.x | >= 2.0.0 |
438+
| 7.x-8.x | 2.0.1 |
439+
| 9.x | >= 3.0.0 |
439440
440441
## Browser compatibility
441442

composer.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,25 @@
2121
],
2222
"require": {
2323
"php": ">=8.1",
24-
"illuminate/support": "^7.0 || ^8.0",
24+
"illuminate/support": "^9.0",
2525
"psr/http-factory-implementation": "1.0",
26-
"thecodingmachine/safe": "^1.0",
27-
"web-auth/cose-lib": "^3.0",
28-
"web-auth/webauthn-lib": "^3.0",
29-
"web-token/jwt-signature": "^1.3 || ^2.0"
26+
"thecodingmachine/safe": "^2.0",
27+
"web-auth/cose-lib": "^4.0",
28+
"web-auth/webauthn-lib": "^4.0",
29+
"web-token/jwt-signature": "^3.0"
3030
},
3131
"require-dev": {
3232
"ext-sqlite3": "*",
3333
"guzzlehttp/psr7": "^2.1",
3434
"laravel/legacy-factories": "^1.0",
35-
"nunomaduro/larastan": "^1.0",
36-
"ocramius/package-versions": "^1.5 || ^2.0",
37-
"orchestra/testbench": "^5.0 || ^6.0",
35+
"nunomaduro/larastan": "^2.0",
36+
"ocramius/package-versions": "^2.0",
37+
"orchestra/testbench": "^7.0",
3838
"phpstan/phpstan-deprecation-rules": "^1.0",
3939
"phpstan/phpstan-phpunit": "^1.0",
4040
"phpstan/phpstan-strict-rules": "^1.0",
4141
"phpunit/phpunit": "^9.0",
42-
"psalm/plugin-laravel": "^1.4",
43-
"thecodingmachine/phpstan-safe-rule": "^1.0",
44-
"vimeo/psalm": "^4.0"
42+
"thecodingmachine/phpstan-safe-rule": "^1.0"
4543
},
4644
"suggest": {
4745
"guzzlehttp/psr7": "To provide a psr/http-factory-implementation implementation",

src/Auth/EloquentWebAuthnProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Illuminate\Database\Eloquent\ModelNotFoundException;
1010
use LaravelWebauthn\Facades\Webauthn;
1111
use LaravelWebauthn\Services\Webauthn\CredentialAssertionValidator;
12+
use ParagonIE\ConstantTime\Base64UrlSafe;
13+
use Webauthn\Util\Base64;
1214

1315
class EloquentWebAuthnProvider extends EloquentUserProvider
1416
{
@@ -53,7 +55,7 @@ public function retrieveByCredentials(array $credentials)
5355
if ($this->isSignedChallenge($credentials)) {
5456
try {
5557
$webauthnKey = (Webauthn::model())::where([
56-
'credentialId' => $credentials['id'],
58+
'credentialId' => Base64UrlSafe::encode(Base64::decode($credentials['id'])),
5759
])->firstOrFail();
5860

5961
return $this->retrieveById($webauthnKey->user_id);

src/Http/Responses/LockoutResponse.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ public function __construct(LoginRateLimiter $limiter)
3636
*/
3737
public function toResponse($request)
3838
{
39-
return with($this->limiter->availableIn($request), function ($seconds) {
40-
throw ValidationException::withMessages([
41-
Webauthn::username() => [
42-
trans('auth.throttle', [
43-
'seconds' => $seconds,
44-
'minutes' => ceil($seconds / 60),
45-
]),
46-
],
47-
])->status(Response::HTTP_TOO_MANY_REQUESTS);
48-
});
39+
$seconds = $this->limiter->availableIn($request);
40+
throw ValidationException::withMessages([
41+
Webauthn::username() => [
42+
trans('auth.throttle', [
43+
'seconds' => $seconds,
44+
'minutes' => ceil($seconds / 60),
45+
]),
46+
],
47+
])->status(Response::HTTP_TOO_MANY_REQUESTS);
4948
}
5049
}

src/Models/Casts/Base64.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace LaravelWebauthn\Models\Casts;
44

5-
use Base64Url\Base64Url;
65
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6+
use ParagonIE\ConstantTime\Base64UrlSafe;
7+
use Webauthn\Util\Base64 as Base64Webauthn;
78

89
class Base64 implements CastsAttributes
910
{
@@ -18,7 +19,7 @@ class Base64 implements CastsAttributes
1819
*/
1920
public function get($model, $key, $value, $attributes): ?string
2021
{
21-
return $value !== null ? Base64Url::decode($value) : null;
22+
return $value !== null ? Base64Webauthn::decode($value) : null;
2223
}
2324

2425
/**
@@ -32,6 +33,6 @@ public function get($model, $key, $value, $attributes): ?string
3233
*/
3334
public function set($model, $key, $value, $attributes): ?string
3435
{
35-
return $value !== null ? Base64Url::encode($value) : null;
36+
return $value !== null ? Base64UrlSafe::encode($value) : null;
3637
}
3738
}

src/Models/Casts/Uuid.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace LaravelWebauthn\Models\Casts;
44

55
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6-
use Ramsey\Uuid\Uuid as UuidConvert;
7-
use Ramsey\Uuid\UuidInterface;
6+
use Symfony\Component\Uid\AbstractUid;
7+
use Symfony\Component\Uid\Uuid as UuidConvert;
88

99
class Uuid implements CastsAttributes
1010
{
@@ -15,9 +15,9 @@ class Uuid implements CastsAttributes
1515
* @param string $key
1616
* @param mixed $value
1717
* @param array $attributes
18-
* @return \Ramsey\Uuid\UuidInterface|null
18+
* @return \Symfony\Component\Uid\AbstractUid|null
1919
*/
20-
public function get($model, $key, $value, $attributes): ?UuidInterface
20+
public function get($model, $key, $value, $attributes): ?AbstractUid
2121
{
2222
if ($value !== null && UuidConvert::isValid($value)) {
2323
return UuidConvert::fromString($value);
@@ -37,6 +37,6 @@ public function get($model, $key, $value, $attributes): ?UuidInterface
3737
*/
3838
public function set($model, $key, $value, $attributes): ?string
3939
{
40-
return $value instanceof UuidInterface ? $value->toString() : (string) $value;
40+
return (string) $value;
4141
}
4242
}

src/Models/WebauthnKey.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use LaravelWebauthn\Models\Casts\Base64;
88
use LaravelWebauthn\Models\Casts\TrustPath;
99
use LaravelWebauthn\Models\Casts\Uuid;
10-
use Ramsey\Uuid\Uuid as UuidConvert;
10+
use Symfony\Component\Uid\NilUuid;
1111
use Webauthn\PublicKeyCredentialSource;
1212

1313
class WebauthnKey extends Model
@@ -43,7 +43,7 @@ class WebauthnKey extends Model
4343
/**
4444
* The attributes that should be visible in serialization.
4545
*
46-
* @var array
46+
* @var array<int, string>
4747
*/
4848
protected $visible = [
4949
'id',
@@ -57,7 +57,7 @@ class WebauthnKey extends Model
5757
/**
5858
* The attributes that should be cast to native types.
5959
*
60-
* @var array
60+
* @var array<string, string>
6161
*/
6262
protected $casts = [
6363
'counter' => 'integer',
@@ -81,7 +81,7 @@ public function getPublicKeyCredentialSourceAttribute(): PublicKeyCredentialSour
8181
$this->transports,
8282
$this->attestationType,
8383
$this->trustPath,
84-
$this->aaguid ?? UuidConvert::fromString(UuidConvert::NIL),
84+
$this->aaguid ?? new NilUuid(),
8585
$this->credentialPublicKey,
8686
(string) $this->user_id,
8787
$this->counter

src/Services/Webauthn/CreationOptionsFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
6161
$this->publicKeyCredentialRpEntity,
6262
$this->getUserEntity($user),
6363
$this->getChallenge(),
64-
$this->createCredentialParameters(),
65-
$this->timeout
64+
$this->createCredentialParameters()
6665
))
67-
->excludeCredentials($this->getExcludedCredentials($user))
66+
->setTimeout($this->timeout)
67+
->excludeCredentials(...$this->getExcludedCredentials($user))
6868
->setAuthenticatorSelection($this->authenticatorSelectionCriteria)
6969
->setAttestation($this->attestationConveyance);
7070

0 commit comments

Comments
 (0)