-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathAuthenticateAdapter.php
More file actions
68 lines (59 loc) · 2.12 KB
/
Copy pathAuthenticateAdapter.php
File metadata and controls
68 lines (59 loc) · 2.12 KB
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
<?php
declare(strict_types=1);
/**
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Webauthn;
use Webauthn\PublicKeyCredentialRequestOptions;
use Webauthn\PublicKeyCredentialSource;
class AuthenticateAdapter extends BaseAdapter
{
/**
* @return \Webauthn\PublicKeyCredentialRequestOptions
*/
public function getOptions(): PublicKeyCredentialRequestOptions
{
$userEntity = $this->getUserEntity();
$allowed = array_map(function (PublicKeyCredentialSource $credential) {
return $credential->getPublicKeyCredentialDescriptor();
}, $this->repository->findAllForUserEntity($userEntity));
$options = $this->server->generatePublicKeyCredentialRequestOptions(
PublicKeyCredentialRequestOptions::USER_VERIFICATION_REQUIREMENT_PREFERRED, // Default value
$allowed
);
$this->request->getSession()->write(
'Webauthn2fa.authenticateOptions',
$options
);
return $options;
}
/**
* Verify the registration response
*
* @return \Webauthn\PublicKeyCredentialSource
*/
public function verifyResponse(): \Webauthn\PublicKeyCredentialSource
{
$options = $this->request->getSession()->read('Webauthn2fa.authenticateOptions');
return $this->loadAndCheckAssertionResponse($options);
}
/**
* @param \Webauthn\PublicKeyCredentialRequestOptions $options request options
* @return \Webauthn\PublicKeyCredentialSource
*/
protected function loadAndCheckAssertionResponse($options): PublicKeyCredentialSource
{
return $this->server->loadAndCheckAssertionResponse(
json_encode($this->request->getData()),
$options,
$this->getUserEntity(),
$this->request
);
}
}