diff --git a/src/core/login/pages/reconnect/reconnect.ts b/src/core/login/pages/reconnect/reconnect.ts index 4f73c3dc2..9372ed2b7 100644 --- a/src/core/login/pages/reconnect/reconnect.ts +++ b/src/core/login/pages/reconnect/reconnect.ts @@ -88,6 +88,8 @@ export class CoreLoginReconnectPage { this.username = site.infos.username; this.siteUrl = site.infos.siteurl; this.siteName = site.getSiteName(); + + // If login was OAuth we should only reach this page if the OAuth method ID has changed. this.isOAuth = site.isOAuth(); // Show logo instead of avatar if it's a fixed site. diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 8fefd913c..7cd8a740c 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -1086,6 +1086,41 @@ export class CoreLoginHelperProvider { }); } } else { + if (currentSite.isOAuth()) { + // User authenticated using an OAuth method. Check if it's still valid. + const identityProviders = this.getValidIdentityProviders(result.config); + const providerToUse = identityProviders.find((provider) => { + const params = this.urlUtils.extractUrlParams(provider.url); + + return params.id == currentSite.getOAuthId(); + }); + + if (providerToUse) { + if (!this.appProvider.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) { + // Open browser to perform the OAuth. + this.isSSOConfirmShown = true; + + const confirmMessage = this.translate.instant('core.login.' + + (currentSite.isLoggedOut() ? 'loggedoutssodescription' : 'reconnectssodescription')); + + this.domUtils.showConfirm(confirmMessage).then(() => { + this.waitingForBrowser = true; + this.sitesProvider.unsetCurrentSite(); // Unset current site to make authentication work fine. + + this.openBrowserForOAuthLogin(siteUrl, providerToUse, result.config.launchurl, data.pageName, + data.params); + }).catch(() => { + // User cancelled, logout him. + this.sitesProvider.logout(); + }).finally(() => { + this.isSSOConfirmShown = false; + }); + } + + return; + } + } + const info = currentSite.getInfo(); if (typeof info != 'undefined' && typeof info.username != 'undefined') { const rootNavCtrl = this.appProvider.getRootNavController(),