Skip to content

Commit 59620ff

Browse files
committed
MOBILE-2853 login: Open browser to reconnect if oauth is still valid
1 parent f5a28ad commit 59620ff

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/core/login/pages/reconnect/reconnect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class CoreLoginReconnectPage {
8888
this.username = site.infos.username;
8989
this.siteUrl = site.infos.siteurl;
9090
this.siteName = site.getSiteName();
91+
92+
// If login was OAuth we should only reach this page if the OAuth method ID has changed.
9193
this.isOAuth = site.isOAuth();
9294

9395
// Show logo instead of avatar if it's a fixed site.

src/core/login/providers/helper.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,41 @@ export class CoreLoginHelperProvider {
10861086
});
10871087
}
10881088
} else {
1089+
if (currentSite.isOAuth()) {
1090+
// User authenticated using an OAuth method. Check if it's still valid.
1091+
const identityProviders = this.getValidIdentityProviders(result.config);
1092+
const providerToUse = identityProviders.find((provider) => {
1093+
const params = this.urlUtils.extractUrlParams(provider.url);
1094+
1095+
return params.id == currentSite.getOAuthId();
1096+
});
1097+
1098+
if (providerToUse) {
1099+
if (!this.appProvider.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) {
1100+
// Open browser to perform the OAuth.
1101+
this.isSSOConfirmShown = true;
1102+
1103+
const confirmMessage = this.translate.instant('core.login.' +
1104+
(currentSite.isLoggedOut() ? 'loggedoutssodescription' : 'reconnectssodescription'));
1105+
1106+
this.domUtils.showConfirm(confirmMessage).then(() => {
1107+
this.waitingForBrowser = true;
1108+
this.sitesProvider.unsetCurrentSite(); // Unset current site to make authentication work fine.
1109+
1110+
this.openBrowserForOAuthLogin(siteUrl, providerToUse, result.config.launchurl, data.pageName,
1111+
data.params);
1112+
}).catch(() => {
1113+
// User cancelled, logout him.
1114+
this.sitesProvider.logout();
1115+
}).finally(() => {
1116+
this.isSSOConfirmShown = false;
1117+
});
1118+
}
1119+
1120+
return;
1121+
}
1122+
}
1123+
10891124
const info = currentSite.getInfo();
10901125
if (typeof info != 'undefined' && typeof info.username != 'undefined') {
10911126
const rootNavCtrl = this.appProvider.getRootNavController(),

0 commit comments

Comments
 (0)