Skip to content

Commit

Permalink
feat!: remove deprecated PublicKeyCredentialSourceRepository and refa…
Browse files Browse the repository at this point in the history
…ctor all signature methods
  • Loading branch information
asbiin committed Sep 4, 2023
1 parent 270e384 commit 89d01e4
Show file tree
Hide file tree
Showing 51 changed files with 252 additions and 974 deletions.
12 changes: 4 additions & 8 deletions database/migrations/2019_03_29_163611_add_webauthn.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddWebauthn extends Migration
return new class() extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create('webauthn_keys', function (Blueprint $table) {
$table->id();
Expand Down Expand Up @@ -42,11 +40,9 @@ public function up()

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('webauthn_keys');
}
}
};
61 changes: 9 additions & 52 deletions src/Actions/AttemptToAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LaravelWebauthn\Actions;

use Closure;
use Illuminate\Auth\Events\Failed;
use Illuminate\Contracts\Auth\Authenticatable as User;
use Illuminate\Contracts\Auth\StatefulGuard;
Expand All @@ -13,41 +14,18 @@

class AttemptToAuthenticate
{
/**
* The guard implementation.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
*/
protected StatefulGuard $guard;

/**
* The login rate limiter instance.
*
* @var \LaravelWebauthn\Services\LoginRateLimiter
*/
protected LoginRateLimiter $limiter;

/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param \LaravelWebauthn\Services\LoginRateLimiter $limiter
* @return void
*/
public function __construct(StatefulGuard $guard, LoginRateLimiter $limiter)
{
$this->guard = $guard;
$this->limiter = $limiter;
}
public function __construct(
protected StatefulGuard $guard,
protected LoginRateLimiter $limiter
) { }

/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle(Request $request, $next)
public function handle(Request $request, Closure $next): mixed
{
if (Webauthn::$authenticateUsingCallback !== null) {
return $this->handleUsingCustomCallback($request, $next);
Expand All @@ -65,10 +43,6 @@ public function handle(Request $request, $next)

/**
* Attempt to log the user into the application.
*
* @param array $challenge
* @param bool $remember
* @return bool
*/
protected function attemptLogin(array $challenge, bool $remember = false): bool
{
Expand All @@ -77,9 +51,6 @@ protected function attemptLogin(array $challenge, bool $remember = false): bool

/**
* Attempt to validate assertion for authenticated user.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function attemptValidateAssertion(Request $request): bool
{
Expand All @@ -104,12 +75,8 @@ protected function attemptValidateAssertion(Request $request): bool

/**
* Attempt to authenticate using a custom callback.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
protected function handleUsingCustomCallback(Request $request, $next)
protected function handleUsingCustomCallback(Request $request, callable $next): mixed
{
$user = Webauthn::$authenticateUsingCallback !== null
? call_user_func(Webauthn::$authenticateUsingCallback, $request)
Expand All @@ -131,12 +98,9 @@ protected function handleUsingCustomCallback(Request $request, $next)
/**
* Throw a failed authentication validation exception.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedAuthenticationException(Request $request)
protected function throwFailedAuthenticationException(Request $request): void
{
$this->limiter->increment($request);

Expand All @@ -147,12 +111,8 @@ protected function throwFailedAuthenticationException(Request $request)

/**
* Fire the failed authentication attempt event with the given arguments.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @return void
*/
protected function fireFailedEvent(Request $request, ?User $user = null)
protected function fireFailedEvent(Request $request, ?User $user = null): void
{
event(new Failed(config('webauthn.guard'), $user, [
Webauthn::username() => $user !== null
Expand All @@ -163,9 +123,6 @@ protected function fireFailedEvent(Request $request, ?User $user = null)

/**
* Get array of webauthn credentials.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function filterCredentials(Request $request): array
{
Expand Down
4 changes: 0 additions & 4 deletions src/Actions/DeleteKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class DeleteKey
{
/**
* Delete a key.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param int $webauthnKeyId
* @return void
*/
public function __invoke(User $user, int $webauthnKeyId): void
{
Expand Down
24 changes: 5 additions & 19 deletions src/Actions/EnsureLoginIsNotThrottled.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,25 @@

namespace LaravelWebauthn\Actions;

use Closure;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Http\Request;
use LaravelWebauthn\Contracts\LockoutResponse;
use LaravelWebauthn\Services\LoginRateLimiter;

class EnsureLoginIsNotThrottled
{
/**
* The login rate limiter instance.
*
* @var \LaravelWebauthn\Services\LoginRateLimiter
*/
protected LoginRateLimiter $limiter;

/**
* Create a new class instance.
*
* @param \LaravelWebauthn\Services\LoginRateLimiter $limiter
* @return void
*/
public function __construct(LoginRateLimiter $limiter)
{
$this->limiter = $limiter;
}
public function __construct(
protected LoginRateLimiter $limiter
) { }

/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle(Request $request, $next)
public function handle(Request $request, Closure $next): mixed
{
if (! $this->limiter->tooManyAttempts($request)) {
return $next($request);
Expand Down
35 changes: 5 additions & 30 deletions src/Actions/LoginUserRetrieval.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,15 @@

class LoginUserRetrieval
{
/**
* The login rate limiter instance.
*
* @var \LaravelWebauthn\Services\LoginRateLimiter
*/
protected LoginRateLimiter $limiter;

/**
* Create a new controller instance.
*
* @param \LaravelWebauthn\Services\LoginRateLimiter $limiter
* @return void
*/
public function __construct(LoginRateLimiter $limiter)
{
$this->limiter = $limiter;
}
public function __construct(
protected LoginRateLimiter $limiter
) { }

/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function __invoke(Request $request): ?User
{
Expand All @@ -54,9 +40,6 @@ public function __invoke(Request $request): ?User

/**
* Return the user that should authenticate via WebAuthn.
*
* @param array|null $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
protected function getUserFromCredentials(?array $credentials): ?User
{
Expand All @@ -73,8 +56,6 @@ protected function getUserFromCredentials(?array $credentials): ?User

/**
* Get the User Provider for WebAuthn Authenticatable users.
*
* @return \Illuminate\Contracts\Auth\UserProvider|null
*/
protected function userProvider(): ?UserProvider
{
Expand All @@ -84,12 +65,9 @@ protected function userProvider(): ?UserProvider
/**
* Throw a failed authentication validation exception.
*
* @param \Illuminate\Http\Request $request
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedAuthenticationException(Request $request)
protected function throwFailedAuthenticationException(Request $request): void
{
$this->limiter->increment($request);

Expand All @@ -100,11 +78,8 @@ protected function throwFailedAuthenticationException(Request $request)

/**
* Fire the failed authentication attempt event with the given arguments.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function fireFailedEvent(Request $request)
protected function fireFailedEvent(Request $request): void
{
event(new Failed(config('webauthn.guard'), null, [
Webauthn::username() => $request->{Webauthn::username()},
Expand Down
3 changes: 0 additions & 3 deletions src/Actions/PrepareAssertionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ class PrepareAssertionData
{
/**
* Get data to authenticate a user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return PublicKeyCredentialRequestOptions
*/
public function __invoke(User $user): PublicKeyCredentialRequestOptions
{
Expand Down
24 changes: 5 additions & 19 deletions src/Actions/PrepareAuthenticatedSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,23 @@

namespace LaravelWebauthn\Actions;

use Closure;
use Illuminate\Http\Request;
use LaravelWebauthn\Services\LoginRateLimiter;

class PrepareAuthenticatedSession
{
/**
* The login rate limiter instance.
*
* @var \LaravelWebauthn\Services\LoginRateLimiter
*/
protected LoginRateLimiter $limiter;

/**
* Create a new class instance.
*
* @param \LaravelWebauthn\Services\LoginRateLimiter $limiter
* @return void
*/
public function __construct(LoginRateLimiter $limiter)
{
$this->limiter = $limiter;
}
public function __construct(
protected LoginRateLimiter $limiter
) { }

/**
* Handle the incoming request.
*
* @param \Illuminate\Http\Request $request
* @param callable $next
* @return mixed
*/
public function handle(Request $request, $next)
public function handle(Request $request, Closure $next): mixed
{
$request->session()->regenerate();

Expand Down
9 changes: 1 addition & 8 deletions src/Actions/PrepareCreationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class PrepareCreationData
{
/**
* Get data to register a new key.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return PublicKeyCredentialCreationOptions
*/
public function __invoke(User $user): PublicKeyCredentialCreationOptions
{
Expand All @@ -29,13 +26,9 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
/**
* Throw a failed register validation exception.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param Exception|null $e
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedRegisterException(User $user, ?Exception $e = null)
protected function throwFailedRegisterException(User $user, ?Exception $e = null): void
{
WebauthnRegisterFailed::dispatch($user, $e);

Expand Down
4 changes: 0 additions & 4 deletions src/Actions/UpdateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class UpdateKey
{
/**
* Update a key.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param int $webauthnKeyId
* @return \Illuminate\Database\Eloquent\Model
*/
public function __invoke(User $user, int $webauthnKeyId, string $keyName): Model
{
Expand Down
Loading

0 comments on commit 89d01e4

Please sign in to comment.