Skip to content

Commit

Permalink
feat: add login event on eloquent provider login (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jul 30, 2022
1 parent bbf3605 commit 16a720e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Auth/EloquentWebAuthnProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Config\Repository as Config;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use LaravelWebauthn\Events\WebauthnLogin;
use LaravelWebauthn\Facades\Webauthn;
use LaravelWebauthn\Services\Webauthn\CredentialAssertionValidator;
use ParagonIE\ConstantTime\Base64UrlSafe;
Expand Down Expand Up @@ -89,6 +90,8 @@ public function validateCredentials(User $user, array $credentials): bool
{
if ($this->isSignedChallenge($credentials)
&& Webauthn::validateAssertion($user, $credentials)) {
WebauthnLogin::dispatch($user, true);

return true;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Events/WebauthnLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ class WebauthnLogin
*/
public User $user;

/**
* Login via eloquent webauthn provider.
*
* @var bool
*/
public bool $eloquent;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param bool $eloquent
*/
public function __construct(User $user)
public function __construct(User $user, bool $eloquent = false)
{
$this->user = $user;
$this->eloquent = $eloquent;
}
}
3 changes: 1 addition & 2 deletions src/WebauthnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public function register()
__DIR__.'/../config/webauthn.php', 'webauthn'
);

$this->app->bind(StatefulGuard::class, fn () => Auth::guard(config('webauthn.guard', null))
);
$this->app->bind(StatefulGuard::class, fn () => Auth::guard(config('webauthn.guard', null)));
}

/**
Expand Down

0 comments on commit 16a720e

Please sign in to comment.