1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\WebAuthn; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\Director; |
6
|
|
|
use SilverStripe\Core\Injector\Injector; |
7
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader; |
8
|
|
|
use SilverStripe\MFA\Method\Handler\VerifyHandlerInterface; |
9
|
|
|
use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface; |
10
|
|
|
use SilverStripe\MFA\Method\MethodInterface; |
11
|
|
|
use SilverStripe\View\Requirements; |
12
|
|
|
|
13
|
|
|
class Method implements MethodInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Provide a localised name for this MFA Method. |
17
|
|
|
* |
18
|
|
|
* @return string |
19
|
|
|
*/ |
20
|
|
|
public function getName(): string |
21
|
|
|
{ |
22
|
|
|
return _t(__CLASS__ . '.NAME', 'Security key'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get a URL segment for this method. This will be used in URL paths for performing authentication by this method |
27
|
|
|
* |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public function getURLSegment(): string |
31
|
|
|
{ |
32
|
|
|
return 'web-authn'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Return the VerifyLHandler that is used to start and verify log in attempts with this method |
37
|
|
|
* |
38
|
|
|
* @return VerifyHandlerInterface |
39
|
|
|
*/ |
40
|
|
|
public function getVerifyHandler(): VerifyHandlerInterface |
41
|
|
|
{ |
42
|
|
|
return Injector::inst()->create(VerifyHandler::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Return the RegisterHandler that is used to perform registrations with this method |
47
|
|
|
* |
48
|
|
|
* @return RegisterHandlerInterface |
49
|
|
|
*/ |
50
|
|
|
public function getRegisterHandler(): RegisterHandlerInterface |
51
|
|
|
{ |
52
|
|
|
return Injector::inst()->create(RegisterHandler::class); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return a URL to an image to be used as a thumbnail in the MFA verification/registration grid for all MFA methods |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getThumbnail(): string |
61
|
|
|
{ |
62
|
|
|
return (string) ModuleLoader::getModule('silverstripe/webauthn-authenticator') |
63
|
|
|
->getResource('client/dist/images/securityKey.svg') |
64
|
|
|
->getURL(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Leverage the Requirements API to ensure client requirements are included. This is called just after the base |
69
|
|
|
* module requirements are specified |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function applyRequirements(): void |
74
|
|
|
{ |
75
|
|
|
Requirements::javascript('silverstripe/webauthn-authenticator: client/dist/js/bundle.js'); |
76
|
|
|
Requirements::css('silverstripe/webauthn-authenticator: client/dist/styles/bundle.css'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function isAvailable(): bool |
80
|
|
|
{ |
81
|
|
|
return Director::is_https(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getUnavailableMessage(): string |
85
|
|
|
{ |
86
|
|
|
return _t(__CLASS__ . '.REQUIRES_HTTPS', 'This method can only be used over HTTPS.'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|