Merge pull request #3165 from vector-im/remove_login_fallback

Remove login fallback to m.org when authentication failed
This commit is contained in:
ismailgulek
2020-04-28 11:35:51 +03:00
committed by GitHub
2 changed files with 11 additions and 82 deletions
+6
View File
@@ -1,3 +1,9 @@
Changes in 0.11.2 (2020-xx-xx)
===============================================
Bug fix:
* AuthenticationViewController: Remove fallback to matrix.org when authentication failed (PR #3165).
Changes in 0.11.1 (2020-04-24) Changes in 0.11.1 (2020-04-24)
=============================================== ===============================================
@@ -27,12 +27,6 @@
@interface AuthenticationViewController () <AuthFallBackViewControllerDelegate, KeyVerificationCoordinatorBridgePresenterDelegate> @interface AuthenticationViewController () <AuthFallBackViewControllerDelegate, KeyVerificationCoordinatorBridgePresenterDelegate>
{ {
/**
Store the potential login error received by using a default homeserver different from matrix.org
while we retry a login process against the matrix.org HS.
*/
NSError *loginError;
/** /**
The default country code used to initialize the mobile phone number input. The default country code used to initialize the mobile phone number input.
*/ */
@@ -288,16 +282,7 @@
} }
super.authType = authType; super.authType = authType;
// Check a potential stored error.
if (loginError)
{
// Restore the default HS
NSLog(@"[AuthenticationVC] Switch back to default homeserver");
[self setHomeServerTextFieldText:nil];
loginError = nil;
}
if (authType == MXKAuthenticationTypeLogin) if (authType == MXKAuthenticationTypeLogin)
{ {
[self.submitButton setTitle:NSLocalizedStringFromTable(@"auth_login", @"Vector", nil) forState:UIControlStateNormal]; [self.submitButton setTitle:NSLocalizedStringFromTable(@"auth_login", @"Vector", nil) forState:UIControlStateNormal];
@@ -845,76 +830,14 @@
- (void)onFailureDuringAuthRequest:(NSError *)error - (void)onFailureDuringAuthRequest:(NSError *)error
{ {
// Homeserver migration: When the default homeserver url is different from matrix.org, MXError *mxError = [[MXError alloc] initWithNSError:error];
// the login (or forgot pwd) process with an existing matrix.org accounts will then fail. if ([mxError.errcode isEqualToString:kMXErrCodeStringResourceLimitExceeded])
// Patch: Falling back to matrix.org HS so we don't break everyone's logins
if ([self.homeServerTextField.text isEqualToString:self.defaultHomeServerUrl] && ![self.defaultHomeServerUrl isEqualToString:@"https://matrix.org"] && !self.softLogoutCredentials)
{ {
MXError *mxError = [[MXError alloc] initWithNSError:error]; [self showResourceLimitExceededError:mxError.userInfo];
if (self.authType == MXKAuthenticationTypeLogin)
{
if (mxError && [mxError.errcode isEqualToString:kMXErrCodeStringForbidden])
{
// Falling back to matrix.org HS
NSLog(@"[AuthenticationVC] Retry login against matrix.org");
// Store the current error, and change the homeserver url
loginError = error;
[self setHomeServerTextFieldText:@"https://matrix.org"];
// Trigger a new request
[self onButtonPressed:self.submitButton];
return;
}
}
else if (self.authType == MXKAuthenticationTypeForgotPassword)
{
if (mxError && [mxError.errcode isEqualToString:kMXErrCodeStringNotFound])
{
// Sanity check
if ([self.authInputsView isKindOfClass:ForgotPasswordInputsView.class])
{
// Falling back to matrix.org HS
NSLog(@"[AuthenticationVC] Retry forgot password against matrix.org");
// Store the current error, and change the homeserver url
loginError = error;
[self setHomeServerTextFieldText:@"https://matrix.org"];
// Trigger a new request
ForgotPasswordInputsView *authInputsView = (ForgotPasswordInputsView*)self.authInputsView;
[authInputsView.nextStepButton sendActionsForControlEvents:UIControlEventTouchUpInside];
return;
}
}
}
}
// Check whether we were retrying against matrix.org HS
if (loginError)
{
// This is not an existing matrix.org accounts
NSLog(@"[AuthenticationVC] This is not an existing matrix.org accounts");
// Restore the default HS
[self setHomeServerTextFieldText:nil];
// Consider the original login error
[super onFailureDuringAuthRequest:loginError];
loginError = nil;
} }
else else
{ {
MXError *mxError = [[MXError alloc] initWithNSError:error]; [super onFailureDuringAuthRequest:error];
if ([mxError.errcode isEqualToString:kMXErrCodeStringResourceLimitExceeded])
{
[self showResourceLimitExceededError:mxError.userInfo];
}
else
{
[super onFailureDuringAuthRequest:error];
}
} }
} }