Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove login fallback to m.org when authentication failed #3165

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
===============================================

Expand Down
87 changes: 5 additions & 82 deletions Riot/Modules/Authentication/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@

@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.
*/
Expand Down Expand Up @@ -288,16 +282,7 @@ - (void)setAuthType:(MXKAuthenticationType)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)
{
[self.submitButton setTitle:NSLocalizedStringFromTable(@"auth_login", @"Vector", nil) forState:UIControlStateNormal];
Expand Down Expand Up @@ -845,76 +830,14 @@ - (IBAction)onButtonPressed:(id)sender

- (void)onFailureDuringAuthRequest:(NSError *)error
{
// Homeserver migration: When the default homeserver url is different from matrix.org,
// the login (or forgot pwd) process with an existing matrix.org accounts will then fail.
// 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];

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)
MXError *mxError = [[MXError alloc] initWithNSError:error];
if ([mxError.errcode isEqualToString:kMXErrCodeStringResourceLimitExceeded])
{
// 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;
[self showResourceLimitExceededError:mxError.userInfo];
}
else
{
MXError *mxError = [[MXError alloc] initWithNSError:error];
if ([mxError.errcode isEqualToString:kMXErrCodeStringResourceLimitExceeded])
{
[self showResourceLimitExceededError:mxError.userInfo];
}
else
{
[super onFailureDuringAuthRequest:error];
}
[super onFailureDuringAuthRequest:error];
}
}

Expand Down