| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Auth\Hook; |
| 4 | |
| 5 | use MediaWiki\Auth\AuthenticationResponse; |
| 6 | use MediaWiki\Auth\AuthManager; |
| 7 | use MediaWiki\User\UserIdentity; |
| 8 | |
| 9 | /** |
| 10 | * This is a hook handler interface, see docs/Hooks.md. |
| 11 | * Use the hook name "AuthManagerVerifyAuthentication" to register handlers implementing this interface. |
| 12 | * |
| 13 | * @stable to implement |
| 14 | * @ingroup Hooks |
| 15 | */ |
| 16 | interface AuthManagerVerifyAuthenticationHook { |
| 17 | /** |
| 18 | * This hook is called before the end of a successful login or account creation attempt. |
| 19 | * It can be used to deny authentication. |
| 20 | * (For account creation, "before end" means after the primary provider returned |
| 21 | * PASS. For login, it is after all secondaries have passed or abstained.) |
| 22 | * |
| 23 | * The hook is only called during AuthManager workflows (i.e. not when using the |
| 24 | * action=login API). After an account creation (which is implemented internally by |
| 25 | * AuthManager as a separate account creation + login), it is only called for the account |
| 26 | * creation part. It is not called at all for account linking (where AuthManager does not |
| 27 | * do any work). |
| 28 | * |
| 29 | * @param UserIdentity|null $user The user who has successfully authenticated. For login, |
| 30 | * the user will exist at this point (possibly autocreated during the authentication |
| 31 | * process). For account creation, the user will not exist yet, and returning false will |
| 32 | * prevent its creation. (There is no guarantee it will prevent the primary provider from |
| 33 | * creating some sort of central account, though - that probably happened already by the |
| 34 | * time the hook is called.) |
| 35 | * Null is only possible during a login attempt, when the response did not contain a |
| 36 | * username (i.e. the primary provider identified the user via their remote account, but |
| 37 | * did not suggest any local username). When not interrupted by the hook, such a login |
| 38 | * attempt will be treated as a failure but the following login or signup might result |
| 39 | * in the identified remote account being linked to a local one. |
| 40 | * @param AuthenticationResponse &$response For login, the final response returned by |
| 41 | * AuthManager. For account creation, the response returned by the primary provider. |
| 42 | * Always a PASS or (when $user is null) a RESTART. |
| 43 | * When the hook handler returns false, it must replace this with a FAIL response that |
| 44 | * describes the reason for the failure. |
| 45 | * @param AuthManager $authManager The AuthManager instance that is handling the request. |
| 46 | * This can be used to access the request object, or to access authentication session data |
| 47 | * (the hook is guaranteed to be called when the authentication session still exists). |
| 48 | * @param array $info Additional information: |
| 49 | * - 'action': (string) The action being performed, one of the AuthManager::ACTION_* |
| 50 | * constants (LOGIN or CREATE). |
| 51 | * - 'primaryId': (string) The unique ID of the primary authentication provider that |
| 52 | * processed the request. |
| 53 | * @return bool|void True or no return value to continue or false to abort authentication |
| 54 | * (in which case $response must be updated). |
| 55 | * @since 1.43 |
| 56 | */ |
| 57 | public function onAuthManagerVerifyAuthentication( |
| 58 | ?UserIdentity $user, |
| 59 | AuthenticationResponse &$response, |
| 60 | AuthManager $authManager, |
| 61 | array $info |
| 62 | ); |
| 63 | } |