22use Psr\Log\LoggerInterface;
60 $this->
setLogger( LoggerFactory::getInstance(
'authentication' ) );
77 $oathUser = $this->cache->get( $user->
getName() );
79 $oathUser =
new OATHUser( $user,
null );
81 $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
90 $moduleKey =
$res->module;
92 $module = $this->auth->getModuleByKey(
'totp' );
95 $module = $this->auth->getModuleByKey( $moduleKey );
97 if ( $module ===
null ) {
102 $oathUser->setModule( $module );
103 $decodedData = FormatJson::decode(
$res->data, 1 );
104 if ( !isset( $decodedData[
'keys'] ) && $module->getName() ===
'totp' ) {
106 $key = $module->newKey( $decodedData );
107 $oathUser->addKey( $key );
108 } elseif ( is_array( $decodedData[
'keys'] ) ) {
109 foreach ( $decodedData[
'keys'] as $keyData ) {
110 $key = $module->newKey( $keyData );
111 $oathUser->addKey( $key );
116 $this->cache->set( $user->
getName(), $oathUser );
128 if ( !$clientInfo ) {
129 $clientInfo = RequestContext::getMain()->getRequest()->getIP();
132 $data = $user->
getModule()->getDataFromUser( $user );
138 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->
getUser() ),
139 'module' => $user->
getModule()->getName(),
140 'data' => FormatJson::encode( $data )
145 $userName = $user->
getUser()->getName();
146 $this->cache->set( $userName, $user );
148 if ( $prevUser !==
false ) {
149 $this->logger->info(
'OATHAuth updated for {user} from {clientip}', [
151 'clientip' => $clientInfo,
155 $this->logger->info(
'OATHAuth enabled for {user} from {clientip}', [
157 'clientip' => $clientInfo,
166 public function remove(
OATHUser $user, $clientInfo ) {
169 [
'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->
getUser() ) ],
173 $userName = $user->
getUser()->getName();
174 $this->cache->delete( $userName );
176 $this->logger->info(
'OATHAuth disabled for {user} from {clientip}', [
178 'clientip' => $clientInfo,
187 global $wgOATHAuthDatabase;
189 return $this->lb->getConnectionRef( $index, [], $wgOATHAuthDatabase );
197 if ( $row->module !==
'' ) {
200 if ( property_exists( $row,
'secret' ) && $row->secret !==
null ) {
219 if ( property_exists( $row,
'secret' ) && property_exists( $row,
'scratch_tokens' ) ) {
220 return FormatJson::encode( [
221 'secret' => $row->secret,
222 'scratch_tokens' => $row->scratch_tokens
Class representing a cache/ephemeral data store.
The CentralIdLookup service allows for connecting local users with cluster-wide IDs.
Exceptions for config failures.
Group all the pieces relevant to the context of a request into one instance.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getName()
Get the user name, or the IP of an anonymous user.