Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
22
vendor/laravel/passkeys/src/Actions/DeletePasskey.php
vendored
Normal file
22
vendor/laravel/passkeys/src/Actions/DeletePasskey.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Actions;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Laravel\Passkeys\Events\PasskeyDeleted;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
|
||||
class DeletePasskey
|
||||
{
|
||||
/**
|
||||
* Delete the given passkey.
|
||||
*/
|
||||
public function __invoke(Authenticatable $user, Passkey $passkey): void
|
||||
{
|
||||
$passkey->delete();
|
||||
|
||||
PasskeyDeleted::dispatch($user, $passkey);
|
||||
}
|
||||
}
|
||||
129
vendor/laravel/passkeys/src/Actions/GenerateRegistrationOptions.php
vendored
Normal file
129
vendor/laravel/passkeys/src/Actions/GenerateRegistrationOptions.php
vendored
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Actions;
|
||||
|
||||
use Cose\Algorithms;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Passkeys;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use RuntimeException;
|
||||
use Webauthn\AuthenticatorSelectionCriteria;
|
||||
use Webauthn\PublicKeyCredentialCreationOptions;
|
||||
use Webauthn\PublicKeyCredentialDescriptor;
|
||||
use Webauthn\PublicKeyCredentialParameters;
|
||||
use Webauthn\PublicKeyCredentialRpEntity;
|
||||
use Webauthn\PublicKeyCredentialUserEntity;
|
||||
|
||||
class GenerateRegistrationOptions
|
||||
{
|
||||
/**
|
||||
* Generate registration options for a user to create a new passkey.
|
||||
*/
|
||||
public function __invoke(Authenticatable $user): PublicKeyCredentialCreationOptions
|
||||
{
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
throw new RuntimeException('User model must implement the PasskeyUser contract.');
|
||||
}
|
||||
|
||||
// Don't verify the authenticator's attestation certificate chain.
|
||||
$attestation = PublicKeyCredentialCreationOptions::ATTESTATION_CONVEYANCE_PREFERENCE_NONE;
|
||||
|
||||
return PublicKeyCredentialCreationOptions::create(
|
||||
rp: $this->relyingParty(),
|
||||
user: $this->userEntity($user),
|
||||
challenge: random_bytes(32),
|
||||
pubKeyCredParams: $this->supportedAlgorithms(),
|
||||
authenticatorSelection: $this->authenticatorSelection(),
|
||||
attestation: $attestation,
|
||||
excludeCredentials: $this->excludedCredentials($user),
|
||||
timeout: Passkeys::timeout(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the relying party entity.
|
||||
*/
|
||||
protected function relyingParty(): PublicKeyCredentialRpEntity
|
||||
{
|
||||
return PublicKeyCredentialRpEntity::create(
|
||||
name: Passkeys::relyingPartyName(),
|
||||
id: Passkeys::relyingPartyId(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the user entity for registration.
|
||||
*/
|
||||
protected function userEntity(PasskeyUser $user): PublicKeyCredentialUserEntity
|
||||
{
|
||||
return PublicKeyCredentialUserEntity::create(
|
||||
name: $user->getPasskeyUsername(),
|
||||
id: $user->getPasskeyUserHandle(),
|
||||
displayName: $user->getPasskeyDisplayName(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authenticator selection criteria.
|
||||
*
|
||||
* @see https://www.w3.org/TR/webauthn-3/#dictdef-authenticatorselectioncriteria
|
||||
*/
|
||||
public function authenticatorSelection(): AuthenticatorSelectionCriteria
|
||||
{
|
||||
// Allow any authenticator: built-in (Touch ID, Windows Hello) or external (YubiKey).
|
||||
$crossPlatform = AuthenticatorSelectionCriteria::AUTHENTICATOR_ATTACHMENT_NO_PREFERENCE;
|
||||
|
||||
// Require a discoverable credential so the user can sign in without typing a username.
|
||||
$residentKey = AuthenticatorSelectionCriteria::RESIDENT_KEY_REQUIREMENT_REQUIRED;
|
||||
|
||||
// Require user verification (biometric, PIN) rather than just presence (tap).
|
||||
$userVerification = AuthenticatorSelectionCriteria::USER_VERIFICATION_REQUIREMENT_REQUIRED;
|
||||
|
||||
return AuthenticatorSelectionCriteria::create(
|
||||
authenticatorAttachment: $crossPlatform,
|
||||
userVerification: $userVerification,
|
||||
residentKey: $residentKey,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials to exclude from registration. Prevents the same
|
||||
* authenticator from being registered twice.
|
||||
*
|
||||
* @return array<PublicKeyCredentialDescriptor>
|
||||
*/
|
||||
public function excludedCredentials(PasskeyUser $user): array
|
||||
{
|
||||
$type = PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY;
|
||||
|
||||
return $user->passkeys()->get()->map(
|
||||
fn ($passkey): PublicKeyCredentialDescriptor => PublicKeyCredentialDescriptor::create(
|
||||
$type,
|
||||
Base64UrlSafe::decodeNoPadding($passkey->credential_id)
|
||||
)
|
||||
)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the supported public key credential algorithms.
|
||||
*
|
||||
* @return array<PublicKeyCredentialParameters>
|
||||
*/
|
||||
public function supportedAlgorithms(): array
|
||||
{
|
||||
$type = PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY;
|
||||
|
||||
// ES256 (ECDSA) is preferred and supported by most authenticators.
|
||||
// RS256 (RSA) is a fallback for older Windows Hello implementations.
|
||||
$es256 = Algorithms::COSE_ALGORITHM_ES256;
|
||||
$rs256 = Algorithms::COSE_ALGORITHM_RS256;
|
||||
|
||||
return [
|
||||
PublicKeyCredentialParameters::create($type, $es256),
|
||||
PublicKeyCredentialParameters::create($type, $rs256),
|
||||
];
|
||||
}
|
||||
}
|
||||
54
vendor/laravel/passkeys/src/Actions/GenerateVerificationOptions.php
vendored
Normal file
54
vendor/laravel/passkeys/src/Actions/GenerateVerificationOptions.php
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Actions;
|
||||
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Passkeys;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use Webauthn\AuthenticatorSelectionCriteria;
|
||||
use Webauthn\PublicKeyCredentialDescriptor;
|
||||
use Webauthn\PublicKeyCredentialRequestOptions;
|
||||
|
||||
class GenerateVerificationOptions
|
||||
{
|
||||
/**
|
||||
* Generate verification options for passwordless login or user confirmation.
|
||||
*
|
||||
* @see https://www.w3.org/TR/webauthn-3/#dictdef-publickeycredentialrequestoptions
|
||||
*/
|
||||
public function __invoke(?PasskeyUser $user = null): PublicKeyCredentialRequestOptions
|
||||
{
|
||||
return PublicKeyCredentialRequestOptions::create(
|
||||
challenge: random_bytes(32),
|
||||
rpId: Passkeys::relyingPartyId(),
|
||||
allowCredentials: $this->allowCredentials($user),
|
||||
userVerification: AuthenticatorSelectionCriteria::USER_VERIFICATION_REQUIREMENT_REQUIRED,
|
||||
timeout: Passkeys::timeout(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials allowed for verification.
|
||||
*
|
||||
* When no user is provided, uses discoverable credentials for passwordless login.
|
||||
*
|
||||
* @return array<PublicKeyCredentialDescriptor>
|
||||
*/
|
||||
public function allowCredentials(?PasskeyUser $user): array
|
||||
{
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$type = PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY;
|
||||
|
||||
return $user->passkeys()->get()->map(
|
||||
fn ($passkey): PublicKeyCredentialDescriptor => PublicKeyCredentialDescriptor::create(
|
||||
$type,
|
||||
Base64UrlSafe::decodeNoPadding($passkey->credential_id)
|
||||
)
|
||||
)->all();
|
||||
}
|
||||
}
|
||||
111
vendor/laravel/passkeys/src/Actions/StorePasskey.php
vendored
Normal file
111
vendor/laravel/passkeys/src/Actions/StorePasskey.php
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Actions;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Events\PasskeyRegistered;
|
||||
use Laravel\Passkeys\Exceptions\InvalidPasskeyException;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
use Laravel\Passkeys\Passkeys;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use RuntimeException;
|
||||
use Webauthn\AuthenticatorAttestationResponse;
|
||||
use Webauthn\CredentialRecord;
|
||||
use Webauthn\PublicKeyCredential;
|
||||
use Webauthn\PublicKeyCredentialCreationOptions;
|
||||
|
||||
class StorePasskey
|
||||
{
|
||||
/**
|
||||
* Validate and store a passkey for the user.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
public function __invoke(
|
||||
Authenticatable $user,
|
||||
string $name,
|
||||
PublicKeyCredential $credential,
|
||||
PublicKeyCredentialCreationOptions $options
|
||||
): Passkey {
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
throw new RuntimeException('User model must implement the PasskeyUser contract.');
|
||||
}
|
||||
|
||||
$response = $this->getResponse($credential);
|
||||
|
||||
$source = $this->validate($response, $options);
|
||||
|
||||
$this->ensureCredentialIsUnique($source);
|
||||
|
||||
$passkey = $this->createPasskey($user, $name, $source);
|
||||
|
||||
PasskeyRegistered::dispatch($user, $passkey);
|
||||
|
||||
return $passkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authenticator attestation response from the credential.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
protected function getResponse(PublicKeyCredential $credential): AuthenticatorAttestationResponse
|
||||
{
|
||||
if (! $credential->response instanceof AuthenticatorAttestationResponse) {
|
||||
throw InvalidPasskeyException::make('Unable to register passkey. Please try again.');
|
||||
}
|
||||
|
||||
return $credential->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the credential and return the source.
|
||||
*/
|
||||
protected function validate(
|
||||
AuthenticatorAttestationResponse $response,
|
||||
PublicKeyCredentialCreationOptions $options
|
||||
): CredentialRecord {
|
||||
return WebAuthn::attestationValidator()->check(
|
||||
authenticatorAttestationResponse: $response,
|
||||
publicKeyCredentialCreationOptions: $options,
|
||||
host: Passkeys::relyingPartyId(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the credential is not already registered.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
protected function ensureCredentialIsUnique(CredentialRecord $source): void
|
||||
{
|
||||
$credentialId = Base64UrlSafe::encodeUnpadded($source->publicKeyCredentialId);
|
||||
|
||||
$exists = Passkeys::passkeyModel()::where('credential_id', $credentialId)->exists();
|
||||
|
||||
if ($exists) {
|
||||
throw InvalidPasskeyException::make('Unable to register this passkey.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the passkey record for the user.
|
||||
*/
|
||||
public function createPasskey(
|
||||
PasskeyUser $user,
|
||||
string $name,
|
||||
CredentialRecord $source
|
||||
): Passkey {
|
||||
$credentialId = Base64UrlSafe::encodeUnpadded($source->publicKeyCredentialId);
|
||||
|
||||
return $user->passkeys()->create([
|
||||
'name' => $name,
|
||||
'credential_id' => $credentialId,
|
||||
'credential' => json_decode(WebAuthn::toJson($source), true, flags: JSON_THROW_ON_ERROR),
|
||||
]);
|
||||
}
|
||||
}
|
||||
138
vendor/laravel/passkeys/src/Actions/VerifyPasskey.php
vendored
Normal file
138
vendor/laravel/passkeys/src/Actions/VerifyPasskey.php
vendored
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Events\PasskeyVerified;
|
||||
use Laravel\Passkeys\Exceptions\InvalidPasskeyException;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
use Laravel\Passkeys\Passkeys;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use Webauthn\AuthenticatorAssertionResponse;
|
||||
use Webauthn\CredentialRecord;
|
||||
use Webauthn\PublicKeyCredential;
|
||||
use Webauthn\PublicKeyCredentialRequestOptions;
|
||||
|
||||
class VerifyPasskey
|
||||
{
|
||||
/**
|
||||
* Validate the passkey credential and return the passkey.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
public function __invoke(
|
||||
PublicKeyCredential $credential,
|
||||
PublicKeyCredentialRequestOptions $options,
|
||||
?PasskeyUser $user = null
|
||||
): Passkey {
|
||||
$response = $this->getResponse($credential);
|
||||
|
||||
/** @var Passkey $passkey */
|
||||
$passkey = DB::transaction(function () use ($credential, $options, $user, $response) {
|
||||
$passkey = $this->getPasskey($credential, lock: true);
|
||||
|
||||
$this->ensurePasskeyBelongsToUser($passkey, $user);
|
||||
|
||||
$source = $this->validate($response, $passkey, $options);
|
||||
|
||||
$this->updatePasskey($passkey, $source);
|
||||
|
||||
PasskeyVerified::dispatch($passkey->user, $passkey);
|
||||
|
||||
return $passkey;
|
||||
});
|
||||
|
||||
return $passkey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authenticator assertion response from the credential.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
protected function getResponse(PublicKeyCredential $credential): AuthenticatorAssertionResponse
|
||||
{
|
||||
if (! $credential->response instanceof AuthenticatorAssertionResponse) {
|
||||
throw InvalidPasskeyException::make('Unable to verify passkey. Please try again.');
|
||||
}
|
||||
|
||||
return $credential->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the passkey by credential ID.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
public function getPasskey(PublicKeyCredential $credential, bool $lock = false): Passkey
|
||||
{
|
||||
$credentialId = Base64UrlSafe::encodeUnpadded($credential->rawId);
|
||||
|
||||
$query = Passkeys::passkeyModel()::where('credential_id', $credentialId);
|
||||
|
||||
if ($lock) {
|
||||
$query->lockForUpdate();
|
||||
}
|
||||
|
||||
return $query->first()
|
||||
?? throw InvalidPasskeyException::make('Passkey not recognized. It may have been removed from your account.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the passkey belongs to the expected user.
|
||||
*
|
||||
* @throws InvalidPasskeyException
|
||||
*/
|
||||
public function ensurePasskeyBelongsToUser(Passkey $passkey, ?PasskeyUser $user): void
|
||||
{
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
$identifier = $user->getKey();
|
||||
|
||||
if (! is_scalar($identifier) || (string) $passkey->user_id !== (string) $identifier) {
|
||||
throw InvalidPasskeyException::make('Passkey not recognized. It may have been removed from your account.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the credential against the stored passkey.
|
||||
*/
|
||||
protected function validate(
|
||||
AuthenticatorAssertionResponse $response,
|
||||
Passkey $passkey,
|
||||
PublicKeyCredentialRequestOptions $options
|
||||
): CredentialRecord {
|
||||
$source = WebAuthn::fromJson(
|
||||
json_encode($passkey->credential, JSON_THROW_ON_ERROR),
|
||||
CredentialRecord::class
|
||||
);
|
||||
|
||||
return WebAuthn::assertionValidator()->check(
|
||||
credentialRecord: $source,
|
||||
authenticatorAssertionResponse: $response,
|
||||
publicKeyCredentialRequestOptions: $options,
|
||||
host: Passkeys::relyingPartyId(),
|
||||
userHandle: $source->userHandle,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the passkey with the latest credential data.
|
||||
*
|
||||
* The credential must be persisted after each use to store the updated
|
||||
* signature counter, which is used to detect cloned authenticators.
|
||||
*/
|
||||
public function updatePasskey(Passkey $passkey, CredentialRecord $source): void
|
||||
{
|
||||
$passkey->forceFill([
|
||||
'credential' => json_decode(WebAuthn::toJson($source), true, flags: JSON_THROW_ON_ERROR),
|
||||
'last_used_at' => now(),
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
12
vendor/laravel/passkeys/src/Contracts/PasskeyConfirmationResponse.php
vendored
Normal file
12
vendor/laravel/passkeys/src/Contracts/PasskeyConfirmationResponse.php
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Support\Responsable;
|
||||
|
||||
interface PasskeyConfirmationResponse extends Responsable
|
||||
{
|
||||
//
|
||||
}
|
||||
12
vendor/laravel/passkeys/src/Contracts/PasskeyDeletedResponse.php
vendored
Normal file
12
vendor/laravel/passkeys/src/Contracts/PasskeyDeletedResponse.php
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Support\Responsable;
|
||||
|
||||
interface PasskeyDeletedResponse extends Responsable
|
||||
{
|
||||
//
|
||||
}
|
||||
12
vendor/laravel/passkeys/src/Contracts/PasskeyLoginResponse.php
vendored
Normal file
12
vendor/laravel/passkeys/src/Contracts/PasskeyLoginResponse.php
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Support\Responsable;
|
||||
|
||||
interface PasskeyLoginResponse extends Responsable
|
||||
{
|
||||
//
|
||||
}
|
||||
16
vendor/laravel/passkeys/src/Contracts/PasskeyRegistrationResponse.php
vendored
Normal file
16
vendor/laravel/passkeys/src/Contracts/PasskeyRegistrationResponse.php
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Support\Responsable;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
|
||||
interface PasskeyRegistrationResponse extends Responsable
|
||||
{
|
||||
/**
|
||||
* Set the passkey that was registered.
|
||||
*/
|
||||
public function withPasskey(Passkey $passkey): static;
|
||||
}
|
||||
48
vendor/laravel/passkeys/src/Contracts/PasskeyUser.php
vendored
Normal file
48
vendor/laravel/passkeys/src/Contracts/PasskeyUser.php
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
interface PasskeyUser extends Authenticatable
|
||||
{
|
||||
/**
|
||||
* Get the passkeys associated with the user.
|
||||
*
|
||||
* @return HasMany<Passkey, Model>
|
||||
*
|
||||
* @phpstan-return HasMany<\Laravel\Passkeys\Passkey, Model>
|
||||
*/
|
||||
public function passkeys(): HasMany;
|
||||
|
||||
/**
|
||||
* Determine if the user has any passkeys enabled.
|
||||
*/
|
||||
public function hasPasskeysEnabled(): bool;
|
||||
|
||||
/**
|
||||
* Get the value of the model's primary key.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getKey();
|
||||
|
||||
/**
|
||||
* Get the unique user handle for WebAuthn.
|
||||
*/
|
||||
public function getPasskeyUserHandle(): string;
|
||||
|
||||
/**
|
||||
* Get the display name for WebAuthn registration.
|
||||
*/
|
||||
public function getPasskeyDisplayName(): string;
|
||||
|
||||
/**
|
||||
* Get the username for WebAuthn registration.
|
||||
*/
|
||||
public function getPasskeyUsername(): string;
|
||||
}
|
||||
26
vendor/laravel/passkeys/src/Events/PasskeyDeleted.php
vendored
Normal file
26
vendor/laravel/passkeys/src/Events/PasskeyDeleted.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Events;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
|
||||
class PasskeyDeleted
|
||||
{
|
||||
use Dispatchable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Authenticatable $user,
|
||||
public Passkey $passkey
|
||||
) {
|
||||
//
|
||||
}
|
||||
}
|
||||
26
vendor/laravel/passkeys/src/Events/PasskeyRegistered.php
vendored
Normal file
26
vendor/laravel/passkeys/src/Events/PasskeyRegistered.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Events;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
|
||||
class PasskeyRegistered
|
||||
{
|
||||
use Dispatchable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Authenticatable $user,
|
||||
public Passkey $passkey
|
||||
) {
|
||||
//
|
||||
}
|
||||
}
|
||||
26
vendor/laravel/passkeys/src/Events/PasskeyVerified.php
vendored
Normal file
26
vendor/laravel/passkeys/src/Events/PasskeyVerified.php
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Events;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
|
||||
class PasskeyVerified
|
||||
{
|
||||
use Dispatchable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Authenticatable $user,
|
||||
public Passkey $passkey
|
||||
) {
|
||||
//
|
||||
}
|
||||
}
|
||||
20
vendor/laravel/passkeys/src/Exceptions/InvalidPasskeyException.php
vendored
Normal file
20
vendor/laravel/passkeys/src/Exceptions/InvalidPasskeyException.php
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Exceptions;
|
||||
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class InvalidPasskeyException extends ValidationException
|
||||
{
|
||||
/**
|
||||
* Create a new invalid passkey exception.
|
||||
*/
|
||||
public static function make(string $message = 'Unable to register passkey. Please try again.'): static
|
||||
{
|
||||
return static::withMessages([
|
||||
'credential' => __($message),
|
||||
]);
|
||||
}
|
||||
}
|
||||
74
vendor/laravel/passkeys/src/Http/Controllers/PasskeyConfirmationController.php
vendored
Normal file
74
vendor/laravel/passkeys/src/Http/Controllers/PasskeyConfirmationController.php
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Controllers;
|
||||
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Session\Store as SessionStore;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Passkeys\Actions\GenerateVerificationOptions;
|
||||
use Laravel\Passkeys\Actions\VerifyPasskey;
|
||||
use Laravel\Passkeys\Contracts\PasskeyConfirmationResponse;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Http\Requests\PasskeyVerificationRequest;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use RuntimeException;
|
||||
|
||||
class PasskeyConfirmationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get passkey confirmation options for the authenticated user.
|
||||
*/
|
||||
public function index(Request $request, GenerateVerificationOptions $generate): JsonResponse
|
||||
{
|
||||
$user = Auth::guard(Config::string('passkeys.guard'))->user()
|
||||
?? throw new AuthenticationException;
|
||||
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
throw new RuntimeException('User model must implement the PasskeyUser contract.');
|
||||
}
|
||||
|
||||
$options = $generate($user);
|
||||
|
||||
$serialized = WebAuthn::toJson($options);
|
||||
|
||||
$request->session()->put('passkey.verification_options', $serialized);
|
||||
|
||||
return response()->json([
|
||||
'options' => WebAuthn::toBrowserArray($options),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password via passkey verification.
|
||||
*/
|
||||
public function store(
|
||||
PasskeyVerificationRequest $request,
|
||||
VerifyPasskey $verify,
|
||||
): PasskeyConfirmationResponse {
|
||||
$user = Auth::guard(Config::string('passkeys.guard'))->user()
|
||||
?? throw new AuthenticationException;
|
||||
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
throw new RuntimeException('User model must implement the PasskeyUser contract.');
|
||||
}
|
||||
|
||||
$verify(
|
||||
$request->credential(),
|
||||
$request->verificationOptions(),
|
||||
$user
|
||||
);
|
||||
|
||||
/** @var SessionStore $session */
|
||||
$session = $request->session();
|
||||
|
||||
$session->passwordConfirmed();
|
||||
|
||||
return app(PasskeyConfirmationResponse::class);
|
||||
}
|
||||
}
|
||||
68
vendor/laravel/passkeys/src/Http/Controllers/PasskeyLoginController.php
vendored
Normal file
68
vendor/laravel/passkeys/src/Http/Controllers/PasskeyLoginController.php
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Auth\StatefulGuard;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Passkeys\Actions\GenerateVerificationOptions;
|
||||
use Laravel\Passkeys\Actions\VerifyPasskey;
|
||||
use Laravel\Passkeys\Contracts\PasskeyLoginResponse;
|
||||
use Laravel\Passkeys\Exceptions\InvalidPasskeyException;
|
||||
use Laravel\Passkeys\Http\Requests\PasskeyVerificationRequest;
|
||||
use Laravel\Passkeys\Passkeys;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use RuntimeException;
|
||||
|
||||
class PasskeyLoginController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get passkey login options.
|
||||
*/
|
||||
public function index(Request $request, GenerateVerificationOptions $generate): JsonResponse
|
||||
{
|
||||
$options = $generate();
|
||||
|
||||
$serialized = WebAuthn::toJson($options);
|
||||
|
||||
$request->session()->put('passkey.verification_options', $serialized);
|
||||
|
||||
return response()->json([
|
||||
'options' => WebAuthn::toBrowserArray($options),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the passkey and log the user in.
|
||||
*/
|
||||
public function store(
|
||||
PasskeyVerificationRequest $request,
|
||||
VerifyPasskey $verify,
|
||||
): PasskeyLoginResponse {
|
||||
$passkey = $verify(
|
||||
$request->credential(),
|
||||
$request->verificationOptions()
|
||||
);
|
||||
|
||||
$guard = Auth::guard(Config::string('passkeys.guard'));
|
||||
|
||||
if (! $guard instanceof StatefulGuard) {
|
||||
throw new RuntimeException('Passkeys requires a stateful authentication guard.');
|
||||
}
|
||||
|
||||
if (! Passkeys::allowsLogin($request, $passkey)) {
|
||||
throw InvalidPasskeyException::make('Unable to sign in with this account.');
|
||||
}
|
||||
|
||||
$guard->login($passkey->user, $request->remember());
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return app(PasskeyLoginResponse::class);
|
||||
}
|
||||
}
|
||||
85
vendor/laravel/passkeys/src/Http/Controllers/PasskeyRegistrationController.php
vendored
Normal file
85
vendor/laravel/passkeys/src/Http/Controllers/PasskeyRegistrationController.php
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Controllers;
|
||||
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Passkeys\Actions\DeletePasskey;
|
||||
use Laravel\Passkeys\Actions\GenerateRegistrationOptions;
|
||||
use Laravel\Passkeys\Actions\StorePasskey;
|
||||
use Laravel\Passkeys\Contracts\PasskeyDeletedResponse;
|
||||
use Laravel\Passkeys\Contracts\PasskeyRegistrationResponse;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Http\Requests\PasskeyRegistrationRequest;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use RuntimeException;
|
||||
|
||||
class PasskeyRegistrationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get passkey registration options for the authenticated user.
|
||||
*/
|
||||
public function index(Request $request, GenerateRegistrationOptions $generate): JsonResponse
|
||||
{
|
||||
$user = Auth::guard(Config::string('passkeys.guard'))->user()
|
||||
?? throw new AuthenticationException;
|
||||
|
||||
$options = $generate($user);
|
||||
|
||||
$serialized = WebAuthn::toJson($options);
|
||||
|
||||
$request->session()->put('passkey.registration_options', $serialized);
|
||||
|
||||
return response()->json([
|
||||
'options' => WebAuthn::toBrowserArray($options),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new passkey for the authenticated user.
|
||||
*/
|
||||
public function store(
|
||||
PasskeyRegistrationRequest $request,
|
||||
StorePasskey $storePasskey,
|
||||
): PasskeyRegistrationResponse {
|
||||
$user = Auth::guard(Config::string('passkeys.guard'))->user()
|
||||
?? throw new AuthenticationException;
|
||||
|
||||
$passkey = $storePasskey(
|
||||
$user,
|
||||
$request->string('name')->toString(),
|
||||
$request->credential(),
|
||||
$request->registrationOptions()
|
||||
);
|
||||
|
||||
return app(PasskeyRegistrationResponse::class)->withPasskey($passkey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a passkey for the authenticated user.
|
||||
*/
|
||||
public function destroy(
|
||||
Passkey $passkey,
|
||||
DeletePasskey $deletePasskey
|
||||
): PasskeyDeletedResponse {
|
||||
$user = Auth::guard(Config::string('passkeys.guard'))->user()
|
||||
?? throw new AuthenticationException;
|
||||
|
||||
if (! $user instanceof PasskeyUser) {
|
||||
throw new RuntimeException('User model must implement the PasskeyUser contract.');
|
||||
}
|
||||
|
||||
abort_unless($passkey->user_id === $user->getKey(), 403);
|
||||
|
||||
$deletePasskey($user, $passkey);
|
||||
|
||||
return app(PasskeyDeletedResponse::class);
|
||||
}
|
||||
}
|
||||
89
vendor/laravel/passkeys/src/Http/Requests/PasskeyRegistrationRequest.php
vendored
Normal file
89
vendor/laravel/passkeys/src/Http/Requests/PasskeyRegistrationRequest.php
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use Throwable;
|
||||
use Webauthn\PublicKeyCredential;
|
||||
use Webauthn\PublicKeyCredentialCreationOptions;
|
||||
|
||||
class PasskeyRegistrationRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* The deserialized public key credential.
|
||||
*/
|
||||
protected PublicKeyCredential $publicKeyCredential;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'credential' => ['required', 'array'],
|
||||
'credential.id' => ['required', 'string'],
|
||||
'credential.rawId' => ['required', 'string'],
|
||||
'credential.type' => ['required', 'string', 'in:public-key'],
|
||||
'credential.response' => ['required', 'array'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a passed validation attempt.
|
||||
*/
|
||||
protected function passedValidation(): void
|
||||
{
|
||||
try {
|
||||
$this->publicKeyCredential = WebAuthn::fromJson(
|
||||
json_encode($this->input('credential')) ?: '{}',
|
||||
PublicKeyCredential::class
|
||||
);
|
||||
} catch (Throwable) {
|
||||
throw ValidationException::withMessages([
|
||||
'credential' => __('Invalid credential format.'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the public key credential.
|
||||
*/
|
||||
public function credential(): PublicKeyCredential
|
||||
{
|
||||
return $this->publicKeyCredential;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registration options from the session.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function registrationOptions(): PublicKeyCredentialCreationOptions
|
||||
{
|
||||
/** @var string|null $serialized */
|
||||
$serialized = $this->session()->pull('passkey.registration_options');
|
||||
|
||||
if (! $serialized) {
|
||||
throw ValidationException::withMessages([
|
||||
'credential' => __('Passkey registration session expired. Please try again.'),
|
||||
]);
|
||||
}
|
||||
|
||||
return WebAuthn::fromJson($serialized, PublicKeyCredentialCreationOptions::class);
|
||||
}
|
||||
}
|
||||
97
vendor/laravel/passkeys/src/Http/Requests/PasskeyVerificationRequest.php
vendored
Normal file
97
vendor/laravel/passkeys/src/Http/Requests/PasskeyVerificationRequest.php
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Passkeys\Support\WebAuthn;
|
||||
use Throwable;
|
||||
use Webauthn\PublicKeyCredential;
|
||||
use Webauthn\PublicKeyCredentialRequestOptions;
|
||||
|
||||
class PasskeyVerificationRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* The deserialized public key credential.
|
||||
*/
|
||||
protected PublicKeyCredential $publicKeyCredential;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'credential' => ['required', 'array'],
|
||||
'credential.id' => ['required', 'string'],
|
||||
'credential.rawId' => ['required', 'string'],
|
||||
'credential.type' => ['required', 'string', 'in:public-key'],
|
||||
'credential.response' => ['required', 'array'],
|
||||
'remember' => ['boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a passed validation attempt.
|
||||
*/
|
||||
protected function passedValidation(): void
|
||||
{
|
||||
try {
|
||||
$this->publicKeyCredential = WebAuthn::fromJson(
|
||||
json_encode($this->input('credential')) ?: '{}',
|
||||
PublicKeyCredential::class
|
||||
);
|
||||
} catch (Throwable) {
|
||||
throw ValidationException::withMessages([
|
||||
'credential' => __('Invalid credential format.'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the public key credential.
|
||||
*/
|
||||
public function credential(): PublicKeyCredential
|
||||
{
|
||||
return $this->publicKeyCredential;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user wants to be remembered.
|
||||
*/
|
||||
public function remember(): bool
|
||||
{
|
||||
return $this->boolean('remember', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the verification options from the session.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function verificationOptions(): PublicKeyCredentialRequestOptions
|
||||
{
|
||||
/** @var string|null $serialized */
|
||||
$serialized = $this->session()->pull('passkey.verification_options');
|
||||
|
||||
if (! $serialized) {
|
||||
throw ValidationException::withMessages([
|
||||
'credential' => __('Passkey verification session expired. Please try again.'),
|
||||
]);
|
||||
}
|
||||
|
||||
return WebAuthn::fromJson($serialized, PublicKeyCredentialRequestOptions::class);
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/passkeys/src/Http/Responses/PasskeyConfirmationResponse.php
vendored
Normal file
30
vendor/laravel/passkeys/src/Http/Responses/PasskeyConfirmationResponse.php
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Responses;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Passkeys\Contracts\PasskeyConfirmationResponse as PasskeyConfirmationResponseContract;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PasskeyConfirmationResponse implements PasskeyConfirmationResponseContract
|
||||
{
|
||||
/**
|
||||
* Create an HTTP response that represents the object.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function toResponse($request)
|
||||
{
|
||||
if ($request->wantsJson()) {
|
||||
return new JsonResponse([
|
||||
'redirect' => redirect()->intended()->getTargetUrl(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
return redirect()->intended();
|
||||
}
|
||||
}
|
||||
28
vendor/laravel/passkeys/src/Http/Responses/PasskeyDeletedResponse.php
vendored
Normal file
28
vendor/laravel/passkeys/src/Http/Responses/PasskeyDeletedResponse.php
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Responses;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Passkeys\Contracts\PasskeyDeletedResponse as PasskeyDeletedResponseContract;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PasskeyDeletedResponse implements PasskeyDeletedResponseContract
|
||||
{
|
||||
/**
|
||||
* Create an HTTP response that represents the object.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function toResponse($request)
|
||||
{
|
||||
if ($request->wantsJson()) {
|
||||
return new JsonResponse(['status' => 'passkey-deleted'], 200);
|
||||
}
|
||||
|
||||
return back()->with('status', 'passkey-deleted');
|
||||
}
|
||||
}
|
||||
30
vendor/laravel/passkeys/src/Http/Responses/PasskeyLoginResponse.php
vendored
Normal file
30
vendor/laravel/passkeys/src/Http/Responses/PasskeyLoginResponse.php
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Responses;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Passkeys\Contracts\PasskeyLoginResponse as PasskeyLoginResponseContract;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PasskeyLoginResponse implements PasskeyLoginResponseContract
|
||||
{
|
||||
/**
|
||||
* Create an HTTP response that represents the object.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function toResponse($request)
|
||||
{
|
||||
if ($request->wantsJson()) {
|
||||
return new JsonResponse([
|
||||
'redirect' => redirect()->intended(config('passkeys.redirect', '/'))->getTargetUrl(),
|
||||
], 200);
|
||||
}
|
||||
|
||||
return redirect()->intended(config('passkeys.redirect', '/'));
|
||||
}
|
||||
}
|
||||
51
vendor/laravel/passkeys/src/Http/Responses/PasskeyRegistrationResponse.php
vendored
Normal file
51
vendor/laravel/passkeys/src/Http/Responses/PasskeyRegistrationResponse.php
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Http\Responses;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Laravel\Passkeys\Contracts\PasskeyRegistrationResponse as PasskeyRegistrationResponseContract;
|
||||
use Laravel\Passkeys\Passkey;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class PasskeyRegistrationResponse implements PasskeyRegistrationResponseContract
|
||||
{
|
||||
/**
|
||||
* The passkey that was registered.
|
||||
*/
|
||||
protected ?Passkey $passkey = null;
|
||||
|
||||
/**
|
||||
* Set the passkey that was registered.
|
||||
*/
|
||||
public function withPasskey(Passkey $passkey): static
|
||||
{
|
||||
$this->passkey = $passkey;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HTTP response that represents the object.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function toResponse($request)
|
||||
{
|
||||
if (! $request->wantsJson()) {
|
||||
return back()->with('status', 'passkey-registered');
|
||||
}
|
||||
|
||||
$data = ['status' => 'passkey-registered'];
|
||||
|
||||
if ($this->passkey instanceof Passkey) {
|
||||
$data['id'] = (string) $this->passkey->id;
|
||||
$data['name'] = $this->passkey->name;
|
||||
}
|
||||
|
||||
return new JsonResponse($data, 200);
|
||||
}
|
||||
}
|
||||
92
vendor/laravel/passkeys/src/Passkey.php
vendored
Normal file
92
vendor/laravel/passkeys/src/Passkey.php
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
use Laravel\Passkeys\Support\Aaguids;
|
||||
|
||||
/**
|
||||
* @mixin Builder<Passkey>
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|string $user_id
|
||||
* @property string $name
|
||||
* @property string $credential_id
|
||||
* @property array<string, mixed> $credential
|
||||
* @property Carbon|null $last_used_at
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read PasskeyUser $user
|
||||
* @property-read string|null $authenticator
|
||||
*/
|
||||
class Passkey extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'credential_id',
|
||||
'credential',
|
||||
];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $appends = [
|
||||
'authenticator',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'credential' => 'json',
|
||||
'last_used_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user that owns the passkey.
|
||||
*
|
||||
* @return BelongsTo<Model, $this>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
/** @var class-string<Model> $model */
|
||||
$model = Passkeys::userModel();
|
||||
|
||||
return $this->belongsTo($model, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authenticator name based on the AAGUID.
|
||||
*/
|
||||
protected function authenticator(): Attribute
|
||||
{
|
||||
return Attribute::get(function (): ?string {
|
||||
$aaguid = $this->credential['aaguid'] ?? null;
|
||||
|
||||
if (! is_string($aaguid) || $aaguid === Aaguids::unknown()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Aaguids::labelFor($aaguid);
|
||||
});
|
||||
}
|
||||
}
|
||||
78
vendor/laravel/passkeys/src/PasskeyAuthenticatable.php
vendored
Normal file
78
vendor/laravel/passkeys/src/PasskeyAuthenticatable.php
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Laravel\Passkeys\Contracts\PasskeyUser;
|
||||
|
||||
/**
|
||||
* @phpstan-require-implements PasskeyUser
|
||||
*/
|
||||
trait PasskeyAuthenticatable
|
||||
{
|
||||
/**
|
||||
* Get the passkeys associated with the user.
|
||||
*
|
||||
* @return HasMany<Passkey, Model>
|
||||
*
|
||||
* @phpstan-return HasMany<Passkey, Model>
|
||||
*/
|
||||
public function passkeys(): HasMany
|
||||
{
|
||||
return $this->hasMany(Passkeys::passkeyModel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user has any passkeys enabled.
|
||||
*/
|
||||
public function hasPasskeysEnabled(): bool
|
||||
{
|
||||
return $this->passkeys()->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unique user handle for WebAuthn.
|
||||
*
|
||||
* This should be a stable identifier that does not reveal PII.
|
||||
*/
|
||||
public function getPasskeyUserHandle(): string
|
||||
{
|
||||
return hash_hmac(
|
||||
'sha256',
|
||||
$this->getTable().'|'.$this->getKey(),
|
||||
Config::string('passkeys.user_handle_secret'),
|
||||
binary: true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name for WebAuthn registration.
|
||||
*
|
||||
* Shown prominently in authenticator UIs (registration prompts,
|
||||
* account pickers, password manager entries). Falls back from
|
||||
* `name` to `email` to the auth identifier when columns are absent.
|
||||
*/
|
||||
public function getPasskeyDisplayName(): string
|
||||
{
|
||||
return $this->getAttribute('name')
|
||||
?? $this->getAttribute('email')
|
||||
?? (string) $this->getAuthIdentifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the username for WebAuthn registration.
|
||||
*
|
||||
* Used as the account identifier in authenticator UIs, typically
|
||||
* rendered as the subtitle beneath the display name. Falls back
|
||||
* from `email` to the auth identifier when the column is absent.
|
||||
*/
|
||||
public function getPasskeyUsername(): string
|
||||
{
|
||||
return $this->getAttribute('email')
|
||||
?? (string) $this->getAuthIdentifier();
|
||||
}
|
||||
}
|
||||
191
vendor/laravel/passkeys/src/Passkeys.php
vendored
Normal file
191
vendor/laravel/passkeys/src/Passkeys.php
vendored
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use RuntimeException;
|
||||
|
||||
class Passkeys
|
||||
{
|
||||
/**
|
||||
* The passkey model class name.
|
||||
*
|
||||
* @var class-string<Passkey>
|
||||
*
|
||||
* @phpstan-var class-string<Passkey>
|
||||
*/
|
||||
public static string $passkeyModel = Passkey::class;
|
||||
|
||||
/**
|
||||
* The user model class name.
|
||||
*
|
||||
* @var class-string<Contracts\PasskeyUser>
|
||||
*/
|
||||
public static string $userModel = 'App\\Models\\User';
|
||||
|
||||
/**
|
||||
* Indicates if routes should be registered.
|
||||
*/
|
||||
private static bool $registersRoutes = true;
|
||||
|
||||
/**
|
||||
* Callback to determine if a passkey-verified user should be logged in.
|
||||
*
|
||||
* @var (Closure(Request, Contracts\PasskeyUser, Passkey): bool)|null
|
||||
*/
|
||||
private static ?Closure $authorizeLoginUsing = null;
|
||||
|
||||
/**
|
||||
* Get the relying party ID.
|
||||
*/
|
||||
public static function relyingPartyId(): string
|
||||
{
|
||||
return Config::string('passkeys.relying_party_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the relying party name.
|
||||
*
|
||||
* The RP name is deprecated in the WebAuthn spec as most clients don't display it,
|
||||
* but remains required for backwards compatibility. Defaults to the RP ID.
|
||||
*
|
||||
* @see https://www.w3.org/TR/webauthn-3/#dom-publickeycredentialentity-name
|
||||
*/
|
||||
public static function relyingPartyName(): string
|
||||
{
|
||||
return static::relyingPartyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origins allowed to complete WebAuthn ceremonies.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function allowedOrigins(): array
|
||||
{
|
||||
/** @var list<string> $origins */
|
||||
$origins = array_values(array_filter(
|
||||
Config::array('passkeys.allowed_origins', []),
|
||||
fn ($origin): bool => is_string($origin) && $origin !== '',
|
||||
));
|
||||
|
||||
if ($origins === []) {
|
||||
throw new RuntimeException('At least one passkey allowed origin must be configured.');
|
||||
}
|
||||
|
||||
return $origins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WebAuthn timeout in milliseconds.
|
||||
*
|
||||
* @return positive-int
|
||||
*/
|
||||
public static function timeout(): int
|
||||
{
|
||||
$timeout = Config::integer('passkeys.timeout', 60000);
|
||||
|
||||
if ($timeout < 1) {
|
||||
throw new RuntimeException('Passkey timeout must be a positive integer.');
|
||||
}
|
||||
|
||||
return $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the passkey model class name.
|
||||
*
|
||||
* @return class-string<Passkey>
|
||||
*
|
||||
* @phpstan-return class-string<Passkey>
|
||||
*/
|
||||
public static function passkeyModel(): string
|
||||
{
|
||||
return static::$passkeyModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the passkey model class name.
|
||||
*
|
||||
* @param class-string<Passkey> $model
|
||||
*
|
||||
* @phpstan-param class-string<Passkey> $model
|
||||
*/
|
||||
public static function usePasskeyModel(string $model): void
|
||||
{
|
||||
static::$passkeyModel = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user model class name.
|
||||
*
|
||||
* @return class-string<Contracts\PasskeyUser>
|
||||
*/
|
||||
public static function userModel(): string
|
||||
{
|
||||
return static::$userModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user model class name.
|
||||
*
|
||||
* @param class-string<Contracts\PasskeyUser> $model
|
||||
*/
|
||||
public static function useUserModel(string $model): void
|
||||
{
|
||||
static::$userModel = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback to authorize passkey logins before login.
|
||||
*
|
||||
* @param (callable(Request, Contracts\PasskeyUser, Passkey): bool)|null $callback
|
||||
*/
|
||||
public static function authorizeLoginUsing(?callable $callback): void
|
||||
{
|
||||
self::$authorizeLoginUsing = $callback !== null
|
||||
? Closure::fromCallable($callback)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a passkey-verified user should be allowed to log in.
|
||||
*/
|
||||
public static function allowsLogin(Request $request, Passkey $passkey): bool
|
||||
{
|
||||
if (! self::$authorizeLoginUsing instanceof Closure) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) (self::$authorizeLoginUsing)($request, $passkey->user, $passkey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if Passkeys routes should be registered.
|
||||
*/
|
||||
public static function shouldRegisterRoutes(): bool
|
||||
{
|
||||
return self::$registersRoutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Passkeys to not register its routes.
|
||||
*/
|
||||
public static function ignoreRoutes(): void
|
||||
{
|
||||
self::$registersRoutes = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the package's migrations.
|
||||
*/
|
||||
public static function migrationPath(): string
|
||||
{
|
||||
return __DIR__.'/../database/migrations';
|
||||
}
|
||||
}
|
||||
89
vendor/laravel/passkeys/src/PasskeysServiceProvider.php
vendored
Normal file
89
vendor/laravel/passkeys/src/PasskeysServiceProvider.php
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys;
|
||||
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Passkeys\Contracts\PasskeyConfirmationResponse as PasskeyConfirmationResponseContract;
|
||||
use Laravel\Passkeys\Contracts\PasskeyDeletedResponse as PasskeyDeletedResponseContract;
|
||||
use Laravel\Passkeys\Contracts\PasskeyLoginResponse as PasskeyLoginResponseContract;
|
||||
use Laravel\Passkeys\Contracts\PasskeyRegistrationResponse as PasskeyRegistrationResponseContract;
|
||||
use Laravel\Passkeys\Http\Responses\PasskeyConfirmationResponse;
|
||||
use Laravel\Passkeys\Http\Responses\PasskeyDeletedResponse;
|
||||
use Laravel\Passkeys\Http\Responses\PasskeyLoginResponse;
|
||||
use Laravel\Passkeys\Http\Responses\PasskeyRegistrationResponse;
|
||||
|
||||
class PasskeysServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->mergeConfigFrom(__DIR__.'/../config/passkeys.php', 'passkeys');
|
||||
|
||||
$this->app->singleton(PasskeyLoginResponseContract::class, PasskeyLoginResponse::class);
|
||||
$this->app->singleton(PasskeyConfirmationResponseContract::class, PasskeyConfirmationResponse::class);
|
||||
$this->app->singleton(PasskeyRegistrationResponseContract::class, PasskeyRegistrationResponse::class);
|
||||
$this->app->singleton(PasskeyDeletedResponseContract::class, PasskeyDeletedResponse::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any package services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerPublishing();
|
||||
$this->registerRoutes();
|
||||
$this->registerRouteBindings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the package's publishable resources.
|
||||
*/
|
||||
protected function registerPublishing(): void
|
||||
{
|
||||
if (! $this->app->runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->publishes([
|
||||
__DIR__.'/../config/passkeys.php' => config_path('passkeys.php'),
|
||||
], 'passkeys-config');
|
||||
|
||||
$this->publishesMigrations([
|
||||
Passkeys::migrationPath() => database_path('migrations'),
|
||||
], 'passkeys-migrations');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the package routes.
|
||||
*/
|
||||
protected function registerRoutes(): void
|
||||
{
|
||||
if (Passkeys::shouldRegisterRoutes()) {
|
||||
$this->loadRoutesFrom(__DIR__.'/../routes/routes.php');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the package route bindings.
|
||||
*/
|
||||
protected function registerRouteBindings(): void
|
||||
{
|
||||
Route::bind('passkey', function (string $value): Passkey {
|
||||
$model = Passkeys::passkeyModel();
|
||||
|
||||
$passkey = app($model)->resolveRouteBinding($value);
|
||||
|
||||
if (! $passkey instanceof Passkey) {
|
||||
throw (new ModelNotFoundException)->setModel($model, [$value]);
|
||||
}
|
||||
|
||||
return $passkey;
|
||||
});
|
||||
}
|
||||
}
|
||||
55
vendor/laravel/passkeys/src/Support/Aaguids.php
vendored
Normal file
55
vendor/laravel/passkeys/src/Support/Aaguids.php
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Support;
|
||||
|
||||
/**
|
||||
* AAGUID to authenticator name mapping.
|
||||
*
|
||||
* @see https://github.com/passkeydeveloper/passkey-authenticator-aaguids
|
||||
*/
|
||||
class Aaguids
|
||||
{
|
||||
/**
|
||||
* The cached AAGUID to name mapping.
|
||||
*
|
||||
* @var array<string, string>|null
|
||||
*/
|
||||
protected static ?array $aaguids = null;
|
||||
|
||||
/**
|
||||
* Get the authenticator label for the given AAGUID.
|
||||
*/
|
||||
public static function labelFor(string $aaguid): ?string
|
||||
{
|
||||
return static::all()[$aaguid] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unknown AAGUID value.
|
||||
*/
|
||||
public static function unknown(): string
|
||||
{
|
||||
return '00000000-0000-0000-0000-000000000000';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all AAGUID to name mappings.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function all(): array
|
||||
{
|
||||
/** @var array<string, string> */
|
||||
return static::$aaguids ??= require __DIR__.'/../../resources/aaguids.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the cached AAGUIDs.
|
||||
*/
|
||||
public static function flush(): void
|
||||
{
|
||||
static::$aaguids = null;
|
||||
}
|
||||
}
|
||||
151
vendor/laravel/passkeys/src/Support/WebAuthn.php
vendored
Normal file
151
vendor/laravel/passkeys/src/Support/WebAuthn.php
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Passkeys\Support;
|
||||
|
||||
use Laravel\Passkeys\Passkeys;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use UnexpectedValueException;
|
||||
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
|
||||
use Webauthn\AttestationStatement\NoneAttestationStatementSupport;
|
||||
use Webauthn\AuthenticatorAssertionResponseValidator;
|
||||
use Webauthn\AuthenticatorAttestationResponseValidator;
|
||||
use Webauthn\CeremonyStep\CeremonyStepManagerFactory;
|
||||
use Webauthn\Denormalizer\WebauthnSerializerFactory;
|
||||
|
||||
/**
|
||||
* This class provides a static interface to the webauthn-lib package, handling
|
||||
* serialization, deserialization, and validation of WebAuthn ceremonies.
|
||||
*/
|
||||
final class WebAuthn
|
||||
{
|
||||
/**
|
||||
* The cached serializer instance.
|
||||
*/
|
||||
private static ?SerializerInterface $serializer = null;
|
||||
|
||||
/**
|
||||
* The cached attestation statement support manager.
|
||||
*/
|
||||
private static ?AttestationStatementSupportManager $attestationStatementSupportManager = null;
|
||||
|
||||
/**
|
||||
* Serialize data to JSON.
|
||||
*/
|
||||
public static function toJson(mixed $data): string
|
||||
{
|
||||
return self::serializer()->serialize($data, 'json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize data to a browser-facing array, omitting null values.
|
||||
*
|
||||
* @return array<array-key, mixed>
|
||||
*/
|
||||
public static function toBrowserArray(mixed $data): array
|
||||
{
|
||||
$serializer = self::serializer();
|
||||
assert($serializer instanceof NormalizerInterface);
|
||||
|
||||
$normalized = $serializer->normalize($data, 'json', [
|
||||
AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
|
||||
]);
|
||||
|
||||
if (! is_array($normalized)) {
|
||||
throw new UnexpectedValueException('Serialized WebAuthn data must normalize to an array.');
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize JSON to a specific class.
|
||||
*
|
||||
* @template T of object
|
||||
*
|
||||
* @param class-string<T> $class
|
||||
* @return T
|
||||
*/
|
||||
public static function fromJson(string $json, string $class): mixed
|
||||
{
|
||||
return self::serializer()->deserialize($json, $class, 'json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the attestation response validator for registration ceremonies.
|
||||
*/
|
||||
public static function attestationValidator(): AuthenticatorAttestationResponseValidator
|
||||
{
|
||||
return AuthenticatorAttestationResponseValidator::create(
|
||||
ceremonyStepManager: self::ceremonyStepManagerFactory()->creationCeremony()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the assertion response validator for verification ceremonies.
|
||||
*/
|
||||
public static function assertionValidator(): AuthenticatorAssertionResponseValidator
|
||||
{
|
||||
return AuthenticatorAssertionResponseValidator::create(
|
||||
ceremonyStepManager: self::ceremonyStepManagerFactory()->requestCeremony()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create the ceremony step manager factory.
|
||||
*/
|
||||
private static function ceremonyStepManagerFactory(): CeremonyStepManagerFactory
|
||||
{
|
||||
$factory = new CeremonyStepManagerFactory;
|
||||
|
||||
$factory->setAllowedOrigins(Passkeys::allowedOrigins());
|
||||
|
||||
$factory->setAttestationStatementSupportManager(
|
||||
self::attestationStatementSupportManager()
|
||||
);
|
||||
|
||||
return $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create the attestation statement support manager.
|
||||
*
|
||||
* Only "none" attestation is registered, so we accept passkeys without
|
||||
* verifying hardware attestation certificates from the authenticator.
|
||||
*/
|
||||
private static function attestationStatementSupportManager(): AttestationStatementSupportManager
|
||||
{
|
||||
if (! self::$attestationStatementSupportManager instanceof AttestationStatementSupportManager) {
|
||||
self::$attestationStatementSupportManager = AttestationStatementSupportManager::create();
|
||||
self::$attestationStatementSupportManager->add(NoneAttestationStatementSupport::create());
|
||||
}
|
||||
|
||||
return self::$attestationStatementSupportManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create the serializer instance.
|
||||
*/
|
||||
private static function serializer(): SerializerInterface
|
||||
{
|
||||
if (! self::$serializer instanceof SerializerInterface) {
|
||||
self::$serializer = (new WebauthnSerializerFactory(
|
||||
self::attestationStatementSupportManager()
|
||||
))->create();
|
||||
}
|
||||
|
||||
return self::$serializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the cached instances (useful for testing).
|
||||
*/
|
||||
public static function flush(): void
|
||||
{
|
||||
self::$serializer = null;
|
||||
self::$attestationStatementSupportManager = null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue