From 46a49fbb9d856452580e8ff07185a500ab4861f6 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Thu, 13 Oct 2022 10:17:51 +0200 Subject: gracefully handle invalid usernames from ProviderDetails Previously we treated the case that a configured ProviderDetails returned an invalid username as an irrecoverable error but it makes more sense to just instead ask the user to pick a different username. --- RedirectAuth.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'RedirectAuth.php') diff --git a/RedirectAuth.php b/RedirectAuth.php index cd73e19..0d09f3d 100644 --- a/RedirectAuth.php +++ b/RedirectAuth.php @@ -214,19 +214,15 @@ class RedirectAuthProvider extends AbstractPrimaryAuthenticationProvider { // The external user id has not yet been linked to a wiki account. $user = $userFactory->newFromName($userInfo->userName, UserFactory::RIGOR_CREATABLE); - if ($req instanceof OtherUsernameAuthRequest) { - if ($user == null) { - return AuthenticationResponse::newUI([new OtherUsernameAuthRequest($userInfo)], WfMessage('redirectauth-pick-other-username-invalid')); - } else if ($user->isRegistered()) { - return AuthenticationResponse::newUI([new OtherUsernameAuthRequest($userInfo)], WfMessage('redirectauth-pick-other-username-taken', $userInfo->userName)); - } - } if ($user == null) { - return AuthenticationResponse::newFail(wfMessage('redirectauth-error-invalid-username', 'ProviderDetails')); + return AuthenticationResponse::newUI([new OtherUsernameAuthRequest($userInfo)], WfMessage('redirectauth-pick-other-username-invalid')); } if ($user->isRegistered()) { // namespace collision + if ($req instanceof OtherUsernameAuthRequest) { + return AuthenticationResponse::newUI([new OtherUsernameAuthRequest($userInfo)], WfMessage('redirectauth-pick-other-username-taken', $userInfo->userName)); + } // We create the link manually because if the system message contained [[User:$1|]] MediaWiki would create an // action=edit link in case the user page doesn't exist ... and linking an edit page would be confusing. -- cgit v1.2.3