getFirstKey(); if ( !( $key instanceof TOTPKey ) ) { throw new MWException( 'oathauth-invalid-key-type' ); } return [ 'keys' => [ $key->jsonSerialize() ] ]; } /** * @return SecondaryAuthenticationProvider */ public function getSecondaryAuthProvider() { return new TOTPSecondaryAuthenticationProvider(); } /** * @param OATHUser $user * @param array $data * @return bool|int * @throws MWException */ public function verify( OATHUser $user, array $data ) { if ( !isset( $data['token'] ) ) { return false; } $key = $user->getFirstKey(); if ( !( $key instanceof TOTPKey ) ) { return false; } return $key->verify( $data, $user ); } /** * Is this module currently enabled for the given user * * @param OATHUser $user * @return bool */ public function isEnabled( OATHUser $user ) { return $user->getFirstKey() instanceof TOTPKey; } /** * @param string $action * @param OATHUser $user * @param OATHUserRepository $repo * @return IManageForm|null */ public function getManageForm( $action, OATHUser $user, OATHUserRepository $repo ) { $isEnabledForUser = $user->getModule() instanceof self; if ( $action === OATHManage::ACTION_ENABLE && !$isEnabledForUser ) { return new TOTPEnableForm( $user, $repo, $this ); } if ( $action === OATHManage::ACTION_DISABLE && $isEnabledForUser ) { return new TOTPDisableForm( $user, $repo, $this ); } return null; } /** * @inheritDoc */ public function getConfig() { return null; } /** * @inheritDoc */ public function getDescriptionMessage() { return wfMessage( 'oathauth-totp-description' ); } /** * @inheritDoc */ public function getDisableWarningMessage() { return wfMessage( 'oathauth-totp-disable-warning' ); } }