Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
54.55% |
12 / 22 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| RecoveryCodesAuthenticationRequest | |
54.55% |
12 / 22 |
|
33.33% |
1 / 3 |
9.38 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| describeCredentials | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getFieldInfo | |
64.71% |
11 / 17 |
|
0.00% |
0 / 1 |
4.70 | |||
| 1 | <?php |
| 2 | declare( strict_types=1 ); |
| 3 | /** |
| 4 | * @license GPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Extension\OATHAuth\Auth; |
| 8 | |
| 9 | use MediaWiki\Auth\AuthenticationRequest; |
| 10 | use MediaWiki\Language\RawMessage; |
| 11 | |
| 12 | /** |
| 13 | * AuthManager value object for the Recovery Codes second factor of authentication: |
| 14 | * a pre-generated recovery code (aka scratch token) that is created whenever an OATH |
| 15 | * user enables at least one form of 2FA (TOTP, WebAuthn, etc.) and is regenerated upon |
| 16 | * each successful usage of a recovery code. |
| 17 | */ |
| 18 | class RecoveryCodesAuthenticationRequest extends AuthenticationRequest { |
| 19 | public string $RecoveryCode; |
| 20 | |
| 21 | public function __construct( |
| 22 | public bool $initialCodesOnly = false |
| 23 | ) { |
| 24 | } |
| 25 | |
| 26 | /** @inheritDoc */ |
| 27 | public function describeCredentials() { |
| 28 | return [ |
| 29 | 'provider' => wfMessage( 'oathauth-describe-provider' ), |
| 30 | 'account' => new RawMessage( '$1', [ $this->username ] ), |
| 31 | ] + parent::describeCredentials(); |
| 32 | } |
| 33 | |
| 34 | /** @inheritDoc */ |
| 35 | public function getFieldInfo() { |
| 36 | $fields = []; |
| 37 | if ( $this->initialCodesOnly ) { |
| 38 | $fields['info-temporary-recovery-code'] = [ |
| 39 | 'type' => 'null', |
| 40 | 'value' => wfMessage( 'oathauth-auth-initial-recovery-code-info' ) |
| 41 | ]; |
| 42 | } |
| 43 | |
| 44 | return $fields + [ |
| 45 | 'RecoveryCode' => [ |
| 46 | 'type' => 'string', |
| 47 | 'label' => $this->initialCodesOnly ? |
| 48 | wfMessage( 'oathauth-auth-initial-recovery-code-label' ) : |
| 49 | wfMessage( 'oathauth-auth-recovery-code-label' ), |
| 50 | 'help' => $this->initialCodesOnly ? |
| 51 | wfMessage( 'oathauth-auth-initial-recovery-code-help' ) : |
| 52 | wfMessage( 'oathauth-auth-recovery-code-help' ), |
| 53 | ] |
| 54 | ]; |
| 55 | } |
| 56 | } |