MediaWiki  1.34.0
TOTPSecondaryAuthenticationProvider.php
Go to the documentation of this file.
1 <?php
20 
27 use Message;
28 use User;
29 
40 
47  public function getAuthenticationRequests( $action, array $options ) {
48  switch ( $action ) {
50  // don't ask for anything initially so the second factor is on a separate screen
51  return [];
52  default:
53  return [];
54  }
55  }
56 
65  public function beginSecondaryAuthentication( $user, array $reqs ) {
66  $userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
67  $authUser = $userRepo->findByUser( $user );
68 
69  if ( !( $authUser->getModule() instanceof TOTP ) ) {
71  } else {
73  wfMessage( 'oathauth-auth-ui' ), 'warning' );
74  }
75  }
76 
81  public function continueSecondaryAuthentication( $user, array $reqs ) {
83  $request = AuthenticationRequest::getRequestByClass( $reqs, TOTPAuthenticationRequest::class );
84  if ( !$request ) {
86  wfMessage( 'oathauth-login-failed' ), 'error' );
87  }
88 
89  $userRepo = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' );
90  $authUser = $userRepo->findByUser( $user );
91  $token = $request->OATHToken;
92 
93  if ( !( $authUser->getModule() instanceof TOTP ) ) {
94  $this->logger->warning( 'Two-factor authentication was disabled mid-authentication for '
95  . $user->getName() );
97  }
98 
99  // Don't increase pingLimiter, just check for limit exceeded.
100  if ( $user->pingLimiter( 'badoath', 0 ) ) {
102  [ new TOTPAuthenticationRequest() ],
103  new Message(
104  'oathauth-throttled',
105  // Arbitrary duration given here
106  [ Message::durationParam( 60 ) ]
107  ), 'error' );
108  }
109 
110  if ( $authUser->getModule()->verify( $authUser, [ 'token' => $token ] ) ) {
112  } else {
114  wfMessage( 'oathauth-login-failed' ), 'error' );
115  }
116  }
117 
125  public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
127  }
128 }
MediaWiki\Auth\AbstractSecondaryAuthenticationProvider
A base class that implements some of the boilerplate for a SecondaryAuthenticationProvider.
Definition: AbstractSecondaryAuthenticationProvider.php:30
MediaWiki\Extension\OATHAuth\Auth\TOTPAuthenticationRequest
AuthManager value object for the TOTP second factor of an authentication: a pseudorandom token that i...
Definition: TOTPAuthenticationRequest.php:29
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider\beginSecondaryAuthentication
beginSecondaryAuthentication( $user, array $reqs)
If the user has enabled two-factor authentication, request a second factor.
Definition: TOTPSecondaryAuthenticationProvider.php:65
MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider\getAuthenticationRequests
getAuthenticationRequests( $action, array $options)
Definition: TOTPSecondaryAuthenticationProvider.php:47
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1264
MediaWiki\Extension\OATHAuth\Auth
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: SecondaryAuthenticationProvider.php:3
MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider\continueSecondaryAuthentication
continueSecondaryAuthentication( $user, array $reqs)
Verify the second factor.
Definition: TOTPSecondaryAuthenticationProvider.php:81
Message
MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider
AuthManager secondary authentication provider for TOTP second-factor authentication.
Definition: TOTPSecondaryAuthenticationProvider.php:39
MediaWiki\Auth\AuthenticationRequest\getRequestByClass
static getRequestByClass(array $reqs, $class, $allowSubclasses=false)
Select a request by class name.
Definition: AuthenticationRequest.php:263
MediaWiki\Extension\OATHAuth\Module\TOTP
Definition: TOTP.php:18
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition: MediaWikiServices.php:138
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
MediaWiki\Auth\AuthenticationResponse
This is a value object to hold authentication response data.
Definition: AuthenticationResponse.php:37
MediaWiki\Auth\AuthManager
This serves as the entry point to the authentication system.
Definition: AuthManager.php:85
MediaWiki\$action
string $action
Cache what action this request is.
Definition: MediaWiki.php:48
MediaWiki\Auth\AuthManager\ACTION_LOGIN
const ACTION_LOGIN
Log in with an existing (not necessarily local) user.
Definition: AuthManager.php:87
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\AuthenticationResponse\newUI
static newUI(array $reqs, Message $msg, $msgtype='warning')
Definition: AuthenticationResponse.php:183
MediaWiki\Extension\OATHAuth\Auth\TOTPSecondaryAuthenticationProvider\beginSecondaryAccountCreation
beginSecondaryAccountCreation( $user, $creator, array $reqs)
Definition: TOTPSecondaryAuthenticationProvider.php:125
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:37