Debian Codegraph @

extensions/OATHAuth/src/Auth/SecondaryAuthenticationProvider.php

raw symbols SCIP
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 * @param string $action
16 * @param array $options
17 *
18 * @return array
19 */
20 public function getAuthenticationRequests( $action, array $options ) {
21 return [];
22 }
23
24 /**
25 * @param User $user
26 * @param User $creator
27 * @param array|AuthenticationRequest[] $reqs
28 * @return AuthenticationResponse
29 */
30 public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
31 return AuthenticationResponse::newAbstain();
32 }
33
34 /**
35 * If the user has enabled two-factor authentication, request a second factor.
36 *
37 * @param User $user
38 * @param array $reqs
39 *
40 * @return AuthenticationResponse
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 * Verify the second factor.
57 * @inheritDoc
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 * @param IModule $module
74 * @return AbstractSecondaryAuthenticationProvider
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 }