From 99a31cab007bdd0febd31a3618f83d1812852957 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Thu, 25 Jan 2024 13:35:26 +0100 Subject: [PATCH] Failure when finding a refresh token in a non OIDC login (#2377) Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> --- .../SoftLogoutScreenCoordinator.swift | 4 ++++ .../Authentication/AuthenticationServiceProxy.swift | 12 ++++++++++++ .../AuthenticationServiceProxyProtocol.swift | 2 +- changelog.d/2365.bugfix | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 changelog.d/2365.bugfix diff --git a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift index 16fc75d76..fc0617e6d 100644 --- a/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift +++ b/ElementX/Sources/Screens/Authentication/SoftLogoutScreen/SoftLogoutScreenCoordinator.swift @@ -186,6 +186,10 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol { case .oidcError(.userCancellation): // No need to show an error, the user cancelled authentication. break + case .sessionTokenRefreshNotSupported: + // We should display a specific error saying that we do not support this kind of login + // But the copy is TBD + viewModel.displayError(.alert(L10n.errorUnknown)) default: viewModel.displayError(.alert(L10n.errorUnknown)) } diff --git a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift index 77804ecda..79e4d2597 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxy.swift @@ -122,6 +122,18 @@ class AuthenticationServiceProxy: AuthenticationServiceProxyProtocol { deviceId: deviceID) } + let refreshToken = try? await Task.dispatch(on: .global()) { + try client.session().refreshToken + } + + if refreshToken != nil { + MXLog.warning("Refresh token found for a non oidc session, can't restore session, logging out") + _ = await Task.dispatch(on: .global()) { + try? client.logout() + } + return .failure(.sessionTokenRefreshNotSupported) + } + return await userSession(for: client) } catch { MXLog.error("Failed logging in with error: \(error)") diff --git a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift index c8fc7ce39..cf9a34f6b 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationServiceProxyProtocol.swift @@ -34,8 +34,8 @@ enum AuthenticationServiceError: Error { case slidingSyncNotAvailable case accountDeactivated case failedLoggingIn - case isOnWaitlist + case sessionTokenRefreshNotSupported } protocol AuthenticationServiceProxyProtocol { diff --git a/changelog.d/2365.bugfix b/changelog.d/2365.bugfix new file mode 100644 index 000000000..36eb50652 --- /dev/null +++ b/changelog.d/2365.bugfix @@ -0,0 +1 @@ +If a refresh token is found in a non OIDC session, the app will be logged out. \ No newline at end of file