| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\OATHAuth\Auth; |
| 4 |
|
| 5 |
use MediaWiki\Auth\AbstractSecondaryAuthenticationProvider; |
| 6 |
use MediaWiki\Auth\AuthenticationRequest; |
| 7 |
use MediaWiki\Auth\AuthenticationResponse; |
| 8 |
use MediaWiki\Extension\OATHAuth\IModule; |
| 9 |
use MediaWiki\Extension\OATHAuth\OATHAuth; |
| 10 |
use MediaWiki\MediaWikiServices; |
| 11 |
use MediaWiki\User\User; |
| 12 |
|
| 13 |
class SecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public function getAuthenticationRequests( $action, array $options ) { |
| 21 |
return []; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) { |
| 31 |
return AuthenticationResponse::newAbstain(); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function beginSecondaryAuthentication( $user, array $reqs ) { |
| 43 |
$authUser = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' ) |
| 44 |
->findByUser( $user ); |
| 45 |
|
| 46 |
$module = $authUser->getModule(); |
| 47 |
if ( $module === null ) { |
| 48 |
return AuthenticationResponse::newAbstain(); |
| 49 |
} |
| 50 |
|
| 51 |
return $this->getProviderForModule( $module ) |
| 52 |
->beginSecondaryAuthentication( $user, $reqs ); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public function continueSecondaryAuthentication( $user, array $reqs ) { |
| 60 |
$authUser = MediaWikiServices::getInstance()->getService( 'OATHUserRepository' ) |
| 61 |
->findByUser( $user ); |
| 62 |
|
| 63 |
$module = $authUser->getModule(); |
| 64 |
$provider = $this->getProviderForModule( $module ); |
| 65 |
$response = $provider->continueSecondaryAuthentication( $user, $reqs ); |
| 66 |
if ( $response->status === AuthenticationResponse::PASS ) { |
| 67 |
$user->getRequest()->getSession()->set( OATHAuth::AUTHENTICATED_OVER_2FA, true ); |
| 68 |
} |
| 69 |
return $response; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
private function getProviderForModule( IModule $module ) { |
| 77 |
$provider = $module->getSecondaryAuthProvider(); |
| 78 |
$services = MediaWikiServices::getInstance(); |
| 79 |
$provider->init( |
| 80 |
$this->logger, |
| 81 |
$this->manager, |
| 82 |
$services->getHookContainer(), |
| 83 |
$this->config, |
| 84 |
$services->getUserNameUtils() |
| 85 |
); |
| 86 |
return $provider; |
| 87 |
} |
| 88 |
} |