-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
AuthenticateController.php
82 lines (71 loc) · 2.73 KB
/
AuthenticateController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace LaravelWebauthn\Http\Controllers;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Routing\Controller;
use LaravelWebauthn\Actions\AttemptToAuthenticate;
use LaravelWebauthn\Actions\EnsureLoginIsNotThrottled;
use LaravelWebauthn\Actions\LoginUserRetrieval;
use LaravelWebauthn\Actions\PrepareAssertionData;
use LaravelWebauthn\Actions\PrepareAuthenticatedSession;
use LaravelWebauthn\Contracts\LoginSuccessResponse;
use LaravelWebauthn\Contracts\LoginViewResponse;
use LaravelWebauthn\Http\Requests\WebauthnLoginAttemptRequest;
use LaravelWebauthn\Http\Requests\WebauthnLoginRequest;
use LaravelWebauthn\Services\Webauthn;
class AuthenticateController extends Controller
{
/**
* Show the login Webauthn request after a login authentication.
*/
public function create(WebauthnLoginAttemptRequest $request): LoginViewResponse
{
$user = $this->createPipeline($request)->then(function ($request) {
return app(LoginUserRetrieval::class)($request);
});
$publicKey = app(PrepareAssertionData::class)($user);
return app(LoginViewResponse::class)
->setPublicKey($request, $publicKey);
}
/**
* Get the authentication pipeline instance.
*/
protected function createPipeline(WebauthnLoginAttemptRequest $request): Pipeline
{
return (new Pipeline(app()))
->send($request)
->through(array_filter([
config('webauthn.limiters.login') !== null ? null : EnsureLoginIsNotThrottled::class,
]));
}
/**
* Authenticate a webauthn request.
*/
public function store(WebauthnLoginRequest $request): LoginSuccessResponse
{
return $this->loginPipeline($request)->then(function ($request) {
Webauthn::login($request->user());
return app(LoginSuccessResponse::class);
});
}
/**
* Get the authentication pipeline instance.
*/
protected function loginPipeline(WebauthnLoginRequest $request): Pipeline
{
if (Webauthn::$authenticateThroughCallback !== null) {
return (new Pipeline(app()))->send($request)->through(array_filter(
call_user_func(Webauthn::$authenticateThroughCallback, $request)
));
}
if (is_array($pipelines = config('webauthn.pipelines.login'))) {
return (new Pipeline(app()))->send($request)->through(array_filter(
$pipelines
));
}
return (new Pipeline(app()))->send($request)->through(array_filter([
config('webauthn.limiters.login') !== null ? null : EnsureLoginIsNotThrottled::class,
AttemptToAuthenticate::class,
PrepareAuthenticatedSession::class,
]));
}
}