22 use Psr\Log\LoggerInterface;
76 $oathUser = $this->cache->get( $user->
getName() );
78 $oathUser =
new OATHUser( $user,
null );
89 $moduleKey =
$res->module;
91 $module = $this->auth->getModuleByKey(
'totp' );
94 $module = $this->auth->getModuleByKey( $moduleKey );
96 if ( $module ===
null ) {
101 $oathUser->setModule( $module );
103 if ( !isset( $decodedData[
'keys'] ) && $module->getName() ===
'totp' ) {
105 $key = $module->newKey( $decodedData );
106 $oathUser->addKey( $key );
107 } elseif ( is_array( $decodedData[
'keys'] ) ) {
108 foreach ( $decodedData[
'keys'] as $keyData ) {
109 $key = $module->newKey( $keyData );
110 $oathUser->addKey( $key );
115 $this->cache->set( $user->
getName(), $oathUser );
128 $data = $user->
getModule()->getDataFromUser( $user );
135 'module' => $user->
getModule()->getName(),
141 $userName = $user->
getUser()->getName();
142 $this->cache->set( $userName, $user );
144 if ( $prevUser !==
false ) {
145 $this->logger->info(
'OATHAuth updated for {user} from {clientip}', [
147 'clientip' => $clientInfo,
151 $this->logger->info(
'OATHAuth enabled for {user} from {clientip}', [
153 'clientip' => $clientInfo,
162 public function remove(
OATHUser $user, $clientInfo ) {
169 $userName = $user->
getUser()->getName();
170 $this->cache->delete( $userName );
172 $this->logger->info(
'OATHAuth disabled for {user} from {clientip}', [
174 'clientip' => $clientInfo,
183 global $wgOATHAuthDatabase;
185 return $this->lb->getConnectionRef( $index, [], $wgOATHAuthDatabase );
193 if ( $row->module !==
'' ) {
196 if ( property_exists( $row,
'secret' ) && $row->secret !==
null ) {
215 if ( property_exists( $row,
'secret' ) && property_exists( $row,
'scratch_tokens' ) ) {
217 'secret' => $row->secret,
218 'scratch_tokens' => $row->scratch_tokens