Method   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 8

8 Methods

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