/
Method.php
85 lines (75 loc) · 2.31 KB
/
Method.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
83
84
85
<?php declare(strict_types=1);
namespace SilverStripe\WebAuthn;
use Director;
use Injector;
use Requirements;
use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface;
use SilverStripe\MFA\Method\Handler\VerifyHandlerInterface;
use SilverStripe\MFA\Method\MethodInterface;
class Method implements MethodInterface
{
/**
* Provide a localised name for this MFA Method.
*
* @return string
*/
public function getName(): string
{
return _t(__CLASS__ . '.NAME', 'Security key');
}
/**
* Get a URL segment for this method. This will be used in URL paths for performing authentication by this method
*
* @return string
*/
public function getURLSegment(): string
{
return 'web-authn';
}
/**
* Return the VerifyLHandler that is used to start and verify log in attempts with this method
*
* @return VerifyHandlerInterface
*/
public function getVerifyHandler(): VerifyHandlerInterface
{
return Injector::inst()->create(VerifyHandler::class);
}
/**
* Return the RegisterHandler that is used to perform registrations with this method
*
* @return RegisterHandlerInterface
*/
public function getRegisterHandler(): RegisterHandlerInterface
{
return Injector::inst()->create(RegisterHandler::class);
}
/**
* Return a URL to an image to be used as a thumbnail in the MFA verification/registration grid for all MFA methods
*
* @return string
*/
public function getThumbnail(): string
{
return Director::absoluteURL('webauthn-authenticator/client/dist/images/securityKey.svg');
}
/**
* Leverage the Requirements API to ensure client requirements are included. This is called just after the base
* module requirements are specified
*
* @return void
*/
public function applyRequirements(): void
{
Requirements::javascript('webauthn-authenticator/client/dist/js/bundle.js');
Requirements::css('webauthn-authenticator/client/dist/styles/bundle.css');
}
public function isAvailable(): bool
{
return Director::is_https();
}
public function getUnavailableMessage(): string
{
return _t(__CLASS__ . '.REQUIRES_HTTPS', 'This method can only be used over HTTPS.');
}
}