1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\MFA\BackupCode; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Injector\Injector; |
6
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader; |
7
|
|
|
use SilverStripe\MFA\Method\Handler\LoginHandlerInterface; |
8
|
|
|
use SilverStripe\MFA\Method\Handler\RegisterHandlerInterface; |
9
|
|
|
use SilverStripe\MFA\Method\MethodInterface; |
10
|
|
|
|
11
|
|
|
class Method implements MethodInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The number of back-up codes that should be generated for a user. Note that changing this value will not |
15
|
|
|
* regenerate or generate new codes to meet the new number. The user will have to manually regenerate codes to |
16
|
|
|
* receive the new number of codes. |
17
|
|
|
* |
18
|
|
|
* @config |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
private static $backup_code_count = 9; |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The length of each individual backup code |
25
|
|
|
* |
26
|
|
|
* @config |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private static $backup_code_length = 6; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get a URL segment for this method. This will be used in URL paths for performing authentication by this method |
33
|
|
|
* |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
public function getURLSegment(): string |
37
|
|
|
{ |
38
|
|
|
return 'backup-codes'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Return the LoginHandler that is used to start and verify login attempts with this method |
43
|
|
|
* |
44
|
|
|
* @return LoginHandlerInterface |
45
|
|
|
*/ |
46
|
|
|
public function getLoginHandler(): LoginHandlerInterface |
47
|
|
|
{ |
48
|
|
|
return Injector::inst()->create(LoginHandler::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Return the RegisterHandler that is used to perform registrations with this method |
53
|
|
|
* |
54
|
|
|
* @return RegisterHandlerInterface |
55
|
|
|
*/ |
56
|
|
|
public function getRegisterHandler(): RegisterHandlerInterface |
57
|
|
|
{ |
58
|
|
|
return Injector::inst()->create(RegisterHandler::class); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getThumbnail(): string |
62
|
|
|
{ |
63
|
|
|
return (string) ModuleLoader::getModule('silverstripe/mfa') |
64
|
|
|
->getResource('client/dist/images/locked-letter.svg') |
65
|
|
|
->getURL(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function applyRequirements(): void |
69
|
|
|
{ |
70
|
|
|
// This authenticator bundles client requirements in the main bundle. |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function isAvailable(): bool |
74
|
|
|
{ |
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getUnavailableMessage(): string |
79
|
|
|
{ |
80
|
|
|
return ''; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|