Skip to content

Commit 16a720e

Browse files
authored
feat: add login event on eloquent provider login (#392)
1 parent bbf3605 commit 16a720e

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Auth/EloquentWebAuthnProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Contracts\Config\Repository as Config;
88
use Illuminate\Contracts\Hashing\Hasher;
99
use Illuminate\Database\Eloquent\ModelNotFoundException;
10+
use LaravelWebauthn\Events\WebauthnLogin;
1011
use LaravelWebauthn\Facades\Webauthn;
1112
use LaravelWebauthn\Services\Webauthn\CredentialAssertionValidator;
1213
use ParagonIE\ConstantTime\Base64UrlSafe;
@@ -89,6 +90,8 @@ public function validateCredentials(User $user, array $credentials): bool
8990
{
9091
if ($this->isSignedChallenge($credentials)
9192
&& Webauthn::validateAssertion($user, $credentials)) {
93+
WebauthnLogin::dispatch($user, true);
94+
9295
return true;
9396
}
9497

src/Events/WebauthnLogin.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@ class WebauthnLogin
1717
*/
1818
public User $user;
1919

20+
/**
21+
* Login via eloquent webauthn provider.
22+
*
23+
* @var bool
24+
*/
25+
public bool $eloquent;
26+
2027
/**
2128
* Create a new event instance.
2229
*
2330
* @param \Illuminate\Contracts\Auth\Authenticatable $user
31+
* @param bool $eloquent
2432
*/
25-
public function __construct(User $user)
33+
public function __construct(User $user, bool $eloquent = false)
2634
{
2735
$this->user = $user;
36+
$this->eloquent = $eloquent;
2837
}
2938
}

src/WebauthnServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public function register()
9494
__DIR__.'/../config/webauthn.php', 'webauthn'
9595
);
9696

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

101100
/**

0 commit comments

Comments
 (0)