forked from DarkGhostHunter/Larapass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfirmsWebAuthn.php
79 lines (67 loc) · 2.02 KB
/
ConfirmsWebAuthn.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
<?php
namespace DarkGhostHunter\Larapass\Http;
use Illuminate\Http\Request;
use DarkGhostHunter\Larapass\Facades\WebAuthn;
use DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable;
trait ConfirmsWebAuthn
{
use WebAuthnRules;
/**
* Display the password confirmation view.
*
* @return \Illuminate\View\View
*/
public function showConfirmForm()
{
return view('larapass::confirm');
}
/**
* Return a request to assert the device.
*
* @param \DarkGhostHunter\Larapass\Contracts\WebAuthnAuthenticatable $user
* @return \Webauthn\PublicKeyCredentialRequestOptions
*/
public function options(WebAuthnAuthenticatable $user)
{
return WebAuthn::generateAssertion($user);
}
/**
* Confirm the device assertion.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
*/
public function confirm(Request $request)
{
$credential = $request->validate($this->assertionRules());
if (WebAuthn::validateAssertion($credential)) {
$this->resetAuthenticatorConfirmationTimeout($request);
return response()->json([
'redirectTo' => redirect()->intended($this->redirectPath())->getTargetUrl()
]);
}
return response()->noContent(422);
}
/**
* Reset the password confirmation timeout.
*
* @param \Illuminate\Http\Request $request
* @return void
*/
protected function resetAuthenticatorConfirmationTimeout(Request $request)
{
$request->session()->put('auth.webauthn.confirm', now()->timestamp);
}
/**
* Get the post recovery redirect path.
*
* @return string
*/
public function redirectPath()
{
if (method_exists($this, 'redirectTo')) {
return $this->redirectTo();
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
}