Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
WebAuthnAddKeyForm | |
0.00% |
0 / 36 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getHTML | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onSuccess | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
onSubmit | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
getDescriptors | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\WebAuthn\HTMLForm; |
4 | |
5 | use MediaWiki\Config\ConfigException; |
6 | use MediaWiki\Context\IContextSource; |
7 | use MediaWiki\Extension\OATHAuth\HTMLForm\OATHAuthOOUIHTMLForm; |
8 | use MediaWiki\Extension\OATHAuth\IModule; |
9 | use MediaWiki\Extension\OATHAuth\OATHUser; |
10 | use MediaWiki\Extension\OATHAuth\OATHUserRepository; |
11 | use MediaWiki\Extension\WebAuthn\Authenticator; |
12 | use MediaWiki\Extension\WebAuthn\HTMLField\AddKeyLayout; |
13 | use MediaWiki\Json\FormatJson; |
14 | use MediaWiki\SpecialPage\SpecialPage; |
15 | use MediaWiki\Status\Status; |
16 | |
17 | class WebAuthnAddKeyForm extends OATHAuthOOUIHTMLForm { |
18 | |
19 | /** |
20 | * @var bool |
21 | */ |
22 | protected $panelPadded = false; |
23 | |
24 | /** |
25 | * @var bool |
26 | */ |
27 | protected $panelFramed = false; |
28 | |
29 | /** |
30 | * @inheritDoc |
31 | */ |
32 | public function __construct( |
33 | OATHUser $oathUser, |
34 | OATHUserRepository $oathRepo, |
35 | IModule $module, |
36 | IContextSource $context |
37 | ) { |
38 | parent::__construct( $oathUser, $oathRepo, $module, $context ); |
39 | |
40 | $this->setId( 'webauthn-add-key-form' ); |
41 | $this->suppressDefaultSubmit(); |
42 | } |
43 | |
44 | /** |
45 | * @param array|bool|Status|string $submitResult |
46 | * @return string |
47 | */ |
48 | public function getHTML( $submitResult ) { |
49 | $this->getOutput()->addModules( 'ext.webauthn.register' ); |
50 | return parent::getHTML( $submitResult ); |
51 | } |
52 | |
53 | /** |
54 | * Add content to output when operation was successful |
55 | */ |
56 | public function onSuccess() { |
57 | $this->getOutput()->redirect( |
58 | SpecialPage::getTitleFor( 'OATHManage' )->getLocalURL() |
59 | ); |
60 | } |
61 | |
62 | /** |
63 | * @param array $formData |
64 | * @return array|bool |
65 | * @throws ConfigException |
66 | */ |
67 | public function onSubmit( array $formData ) { |
68 | if ( !isset( $formData['credential'] ) ) { |
69 | return [ 'oathauth-failedtovalidateoath' ]; |
70 | } |
71 | $credential = $formData['credential']; |
72 | $credential = FormatJson::decode( $credential ); |
73 | $authenticator = Authenticator::factory( $this->getUser(), $this->getRequest() ); |
74 | $registrationResult = $authenticator->continueRegistration( $credential ); |
75 | if ( $registrationResult->isGood() ) { |
76 | return true; |
77 | } |
78 | |
79 | return [ $registrationResult->getMessage() ]; |
80 | } |
81 | |
82 | /** |
83 | * @return array |
84 | */ |
85 | protected function getDescriptors() { |
86 | return [ |
87 | 'name-help' => [ |
88 | 'type' => 'info', |
89 | 'default' => wfMessage( 'webauthn-ui-key-register-help' )->escaped(), |
90 | 'raw' => true, |
91 | 'section' => 'webauthn-add-key-section-name' |
92 | ], |
93 | 'name-layout' => [ |
94 | 'type' => 'null', |
95 | 'class' => AddKeyLayout::class, |
96 | 'raw' => true, |
97 | 'section' => 'webauthn-add-key-section-name' |
98 | ], |
99 | 'credential' => [ |
100 | 'name' => 'credential', |
101 | 'type' => 'hidden', |
102 | 'value' => '' |
103 | ] |
104 | ]; |
105 | } |
106 | } |