diff --git a/src/Key/TOTPKey.php b/src/Key/TOTPKey.php index 5450f340..01a8162e 100644 --- a/src/Key/TOTPKey.php +++ b/src/Key/TOTPKey.php @@ -22,6 +22,7 @@ namespace MediaWiki\Extension\OATHAuth\Key; use Base32\Base32; use jakobo\HOTP\HOTP; use MediaWiki\Extension\OATHAuth\OATHUser; +use MediaWiki\Extension\OATHAuth\OATHUserRepository; use Psr\Log\LoggerInterface; use MediaWiki\Logger\LoggerFactory; use DomainException; @@ -195,6 +196,8 @@ class TOTPKey implements IAuthKey { $auth = MediaWikiServices::getInstance()->getService( 'OATHAuth' ); $module = $auth->getModuleByKey( 'totp' ); + + /** @var OATHUserRepository $userRepo */ $userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' ); $user->addKey( $this ); $user->setModule( $module ); diff --git a/src/OATHUserRepository.php b/src/OATHUserRepository.php index 48d20189..0f1f3d75 100644 --- a/src/OATHUserRepository.php +++ b/src/OATHUserRepository.php @@ -29,6 +29,7 @@ use BagOStuff; use ConfigException; use User; use stdClass; +use RequestContext; class OATHUserRepository { /** @var ILoadBalancer */ @@ -119,11 +120,14 @@ class OATHUserRepository { /** * @param OATHUser $user - * @param string $clientInfo + * @param string|null $clientInfo * @throws ConfigException * @throws MWException */ - public function persist( OATHUser $user, $clientInfo ) { + public function persist( OATHUser $user, $clientInfo = null ) { + if ( !$clientInfo ) { + $clientInfo = RequestContext::getMain()->getRequest()->getIP(); + } $prevUser = $this->findByUser( $user->getUser() ); $data = $user->getModule()->getDataFromUser( $user );