Skip to content

Commit 00dfcc5

Browse files
authored
fix: fix deprecated calls [skip ci] (#457)
1 parent 6c8e089 commit 00dfcc5

File tree

10 files changed

+70
-80
lines changed

10 files changed

+70
-80
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"illuminate/support": "^9.0 || ^10.0",
2525
"psr/http-factory-implementation": "1.0",
2626
"web-auth/cose-lib": "^4.0",
27-
"web-auth/webauthn-lib": "^4.0",
27+
"web-auth/webauthn-lib": "^4.7.1",
2828
"web-token/jwt-signature": "^3.0"
2929
},
3030
"conflict": {

phpunit.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" beStrictAboutTestsThatDoNotTestAnything="true" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage processUncoveredFiles="true">
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage/>
84
<testsuites>
95
<testsuite name="LaravelSabre Tests Suite">
106
<directory suffix="Test.php">./tests</directory>
@@ -15,4 +11,9 @@
1511
<env name="APP_KEY" value="base64:uA/XEme0vpegJz/rKSk3ys2uzEfXZA0Ca2P0e1M8vRU="/>
1612
<env name="DB_CONNECTION" value="testbench"/>
1713
</php>
14+
<source>
15+
<include>
16+
<directory suffix=".php">./src</directory>
17+
</include>
18+
</source>
1819
</phpunit>

src/Models/WebauthnKey.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ public function publicKeyCredentialSource(): Attribute
9090
$this->counter
9191
),
9292
set: function (PublicKeyCredentialSource $value, array $attributes = null): array {
93-
if (((string) Arr::get($attributes, 'user_id')) !== $value->getUserHandle()) {
93+
if (((string) Arr::get($attributes, 'user_id')) !== $value->userHandle) {
9494
throw new WrongUserHandleException();
9595
}
9696

9797
// Set value to attributes using casts
98-
$this->credentialId = $value->getPublicKeyCredentialId();
99-
$this->transports = $value->getTransports();
100-
$this->trustPath = $value->getTrustPath();
101-
$this->aaguid = $value->getAaguid();
102-
$this->credentialPublicKey = $value->getCredentialPublicKey();
103-
$this->counter = $value->getCounter();
98+
$this->credentialId = $value->publicKeyCredentialId;
99+
$this->transports = $value->transports;
100+
$this->trustPath = $value->trustPath;
101+
$this->aaguid = $value->aaguid;
102+
$this->credentialPublicKey = $value->credentialPublicKey;
103+
$this->counter = $value->counter;
104104

105105
return [
106106
'credentialId' => $this->attributes['credentialId'],
107-
'type' => $value->getType(),
107+
'type' => $value->type,
108108
'transports' => $this->attributes['transports'],
109-
'attestationType' => $value->getAttestationType(),
109+
'attestationType' => $value->attestationType,
110110
'trustPath' => $this->attributes['trustPath'],
111111
'aaguid' => $this->attributes['aaguid'],
112112
'credentialPublicKey' => $this->attributes['credentialPublicKey'],

src/Services/Webauthn/CreationOptionsFactory.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ public function __construct(
4040
*/
4141
public function __invoke(User $user): PublicKeyCredentialCreationOptions
4242
{
43-
$publicKey = (new PublicKeyCredentialCreationOptions(
43+
$publicKey = new PublicKeyCredentialCreationOptions(
4444
$this->publicKeyCredentialRpEntity,
4545
$this->getUserEntity($user),
4646
$this->getChallenge(),
47-
$this->createCredentialParameters()
48-
))
49-
->setTimeout($this->timeout)
50-
->excludeCredentials(...$this->getExcludedCredentials($user))
51-
->setAuthenticatorSelection($this->authenticatorSelectionCriteria)
52-
->setAttestation($this->attestationConveyance);
47+
$this->createCredentialParameters(),
48+
$this->authenticatorSelectionCriteria,
49+
$this->attestationConveyance,
50+
$this->getExcludedCredentials($user),
51+
$this->timeout
52+
);
5353

5454
$this->cache->put($this->cacheKey($user), $publicKey->jsonSerialize(), $this->timeout);
5555

src/Services/Webauthn/CredentialAssertionValidator.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,20 @@ protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
6565
*/
6666
protected function getResponse(PublicKeyCredential $publicKeyCredential): AuthenticatorAssertionResponse
6767
{
68-
$response = $publicKeyCredential->getResponse();
69-
7068
// Check if the response is an Authenticator Assertion Response
71-
if (! $response instanceof AuthenticatorAssertionResponse) {
69+
if (! $publicKeyCredential->response instanceof AuthenticatorAssertionResponse) {
7270
throw new ResponseMismatchException('Not an authenticator attestation response');
7371
}
7472

75-
return $response;
73+
return $publicKeyCredential->response;
7674
}
7775

7876
/**
7977
* Get credential source from user and public key.
8078
*/
8179
protected function getCredentialSource(User $user, PublicKeyCredential $publicKeyCredential)
8280
{
83-
$credentialId = $publicKeyCredential->getRawId();
81+
$credentialId = $publicKeyCredential->rawId;
8482

8583
return (Webauthn::model())::where('user_id', $user->getAuthIdentifier())
8684
->where(fn ($query) => $query->where('credentialId', Base64UrlSafe::encode($credentialId))

src/Services/Webauthn/CredentialAttestationValidator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ protected function pullPublicKey(User $user): PublicKeyCredentialCreationOptions
6060
*/
6161
protected function getResponse(PublicKeyCredential $publicKeyCredential): AuthenticatorAttestationResponse
6262
{
63-
$response = $publicKeyCredential->getResponse();
64-
6563
// Check if the response is an Authenticator Attestation Response
66-
if (! $response instanceof AuthenticatorAttestationResponse) {
64+
if (! $publicKeyCredential->response instanceof AuthenticatorAttestationResponse) {
6765
throw new ResponseMismatchException('Not an authenticator attestation response');
6866
}
6967

70-
return $response;
68+
return $publicKeyCredential->response;
7169
}
7270
}

src/Services/Webauthn/CredentialValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function cacheKey(User $user): string
2929
[
3030
self::CACHE_PUBLICKEY_REQUEST,
3131
get_class($user).':'.$user->getAuthIdentifier(),
32-
hash('sha512', $this->request->getHost().'|'.$this->request->ip()),
32+
hash('sha512', $this->request->host().'|'.$this->request->ip()),
3333
]
3434
);
3535
}

src/Services/Webauthn/RequestOptionsFactory.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ public function __construct(
3333
*/
3434
public function __invoke(User $user): PublicKeyCredentialRequestOptions
3535
{
36-
$publicKey = (new PublicKeyCredentialRequestOptions($this->getChallenge()))
37-
->setTimeout($this->timeout)
38-
->allowCredentials(...$this->getAllowedCredentials($user))
39-
->setRpId($this->getRpId())
40-
->setUserVerification($this->userVerification);
36+
$publicKey = new PublicKeyCredentialRequestOptions(
37+
$this->getChallenge(),
38+
$this->getRpId(),
39+
$this->getAllowedCredentials($user),
40+
$this->userVerification,
41+
$this->timeout
42+
);
4143

4244
$this->cache->put($this->cacheKey($user), $publicKey->jsonSerialize(), $this->timeout);
4345

@@ -69,6 +71,6 @@ private function getAllowedCredentials(User $user): array
6971
*/
7072
private function getRpId(): ?string
7173
{
72-
return $this->publicKeyCredentialRpEntity->getId();
74+
return $this->publicKeyCredentialRpEntity->id;
7375
}
7476
}

src/WebauthnServiceProvider.php

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ protected function bindWebAuthnPackage(): void
169169
AttestationObjectLoader::class,
170170
fn ($app) => tap(new AttestationObjectLoader(
171171
$app[AttestationStatementSupportManager::class]
172-
), function ($loader) use ($app) {
173-
$loader->setLogger($app['webauthn.log']);
174-
})
172+
), fn (AttestationObjectLoader $loader) => $loader->setLogger($app['webauthn.log'])
173+
)
175174
);
176175

177176
$this->app->bind(
@@ -186,50 +185,43 @@ protected function bindWebAuthnPackage(): void
186185
null,
187186
null,
188187
$app[ExtensionOutputCheckerHandler::class]
189-
), function ($responseValidator) use ($app) {
190-
$responseValidator->setLogger($app['webauthn.log']);
191-
})
188+
), fn (AuthenticatorAttestationResponseValidator $responseValidator) => $responseValidator->setLogger($app['webauthn.log'])
189+
)
192190
);
193191
$this->app->bind(
194192
AuthenticatorAssertionResponseValidator::class,
195-
fn ($app) => tap(new AuthenticatorAssertionResponseValidator(
193+
fn ($app) => tap((new AuthenticatorAssertionResponseValidator(
196194
null,
197195
null,
198196
$app[ExtensionOutputCheckerHandler::class],
199197
$app[CoseAlgorithmManager::class]
200-
), function ($responseValidator) use ($app) {
201-
$responseValidator->setCounterChecker($app[CounterChecker::class])
202-
->setLogger($app['webauthn.log']);
203-
})
198+
))
199+
->setCounterChecker($app[CounterChecker::class]), fn (AuthenticatorAssertionResponseValidator $responseValidator) => $responseValidator->setLogger($app['webauthn.log'])
200+
)
204201
);
205202
$this->app->bind(
206203
AuthenticatorSelectionCriteria::class,
207-
fn ($app) => tap(new AuthenticatorSelectionCriteria(), function ($authenticatorSelectionCriteria) use ($app) {
208-
$authenticatorSelectionCriteria
209-
->setAuthenticatorAttachment($app['config']->get('webauthn.attachment_mode', 'null'))
210-
->setUserVerification($app['config']->get('webauthn.user_verification', 'preferred'));
211-
212-
if (($userless = $app['config']->get('webauthn.userless')) !== null) {
213-
$authenticatorSelectionCriteria->setResidentKey($userless);
214-
}
215-
})
204+
fn ($app) => new AuthenticatorSelectionCriteria(
205+
$app['config']->get('webauthn.attachment_mode', 'null'),
206+
$app['config']->get('webauthn.user_verification', 'preferred'),
207+
$app['config']->get('webauthn.userless')
208+
)
216209
);
217210

218211
$this->app->bind(
219212
PublicKeyCredentialRpEntity::class,
220213
fn ($app) => new PublicKeyCredentialRpEntity(
221214
$app['config']->get('app.name', 'Laravel'),
222-
$app->make('request')->getHost(),
215+
$app->make('request')->host(),
223216
$app['config']->get('webauthn.icon')
224217
)
225218
);
226219
$this->app->bind(
227220
PublicKeyCredentialLoader::class,
228221
fn ($app) => tap(new PublicKeyCredentialLoader(
229222
$app[AttestationObjectLoader::class]
230-
), function ($loader) use ($app) {
231-
$loader->setLogger($app['webauthn.log']);
232-
})
223+
), fn (PublicKeyCredentialLoader $loader) => $loader->setLogger($app['webauthn.log'])
224+
)
233225
);
234226

235227
$this->app->bind(
@@ -348,14 +340,13 @@ protected function bindPsrInterfaces(): void
348340

349341
private function passwordLessWebauthn(): void
350342
{
351-
$this->app['auth']->provider('webauthn', function ($app, array $config) {
352-
return new EloquentWebAuthnProvider(
353-
$app['config'],
354-
$app[CredentialAssertionValidator::class],
355-
$app[Hasher::class],
356-
$config['model']
357-
);
358-
});
343+
$this->app['auth']->provider('webauthn', fn ($app, array $config) => new EloquentWebAuthnProvider(
344+
$app['config'],
345+
$app[CredentialAssertionValidator::class],
346+
$app[Hasher::class],
347+
$config['model']
348+
)
349+
);
359350
}
360351

361352
/**

tests/Unit/Models/WebauthnKeyTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public function test_deserialize_data()
4242

4343
$publicKeyCredentialSource = $webauthnKey->publicKeyCredentialSource;
4444

45-
$this->assertEquals('a', $publicKeyCredentialSource->getPublicKeyCredentialId());
46-
$this->assertEquals('b', $publicKeyCredentialSource->getType());
47-
$this->assertEquals([], $publicKeyCredentialSource->getTransports());
48-
$this->assertEquals('38195f59-0e5b-4ebf-be46-75664177eeee', $publicKeyCredentialSource->getAaguid());
49-
$this->assertEquals('e', $publicKeyCredentialSource->getCredentialPublicKey());
50-
$this->assertEquals('0', $publicKeyCredentialSource->getUserHandle());
51-
$this->assertEquals(0, $publicKeyCredentialSource->getCounter());
52-
$this->assertEquals('c', $publicKeyCredentialSource->getAttestationType());
53-
$this->assertInstanceOf(\Webauthn\TrustPath\EmptyTrustPath::class, $publicKeyCredentialSource->getTrustPath());
45+
$this->assertEquals('a', $publicKeyCredentialSource->publicKeyCredentialId);
46+
$this->assertEquals('b', $publicKeyCredentialSource->type);
47+
$this->assertEquals([], $publicKeyCredentialSource->transports);
48+
$this->assertEquals('38195f59-0e5b-4ebf-be46-75664177eeee', $publicKeyCredentialSource->aaguid);
49+
$this->assertEquals('e', $publicKeyCredentialSource->credentialPublicKey);
50+
$this->assertEquals('0', $publicKeyCredentialSource->userHandle);
51+
$this->assertEquals(0, $publicKeyCredentialSource->counter);
52+
$this->assertEquals('c', $publicKeyCredentialSource->attestationType);
53+
$this->assertInstanceOf(\Webauthn\TrustPath\EmptyTrustPath::class, $publicKeyCredentialSource->trustPath);
5454
}
5555
}

0 commit comments

Comments
 (0)