commit
bf9d5a5f50
|
@ -92,8 +92,8 @@ export class CoreLoginMethodsComponent implements OnInit {
|
|||
*
|
||||
* @param provider The provider that was clicked.
|
||||
*/
|
||||
oauthClicked(provider: CoreSiteIdentityProvider): void {
|
||||
const result = CoreLoginHelper.openBrowserForOAuthLogin(
|
||||
async oauthClicked(provider: CoreSiteIdentityProvider): Promise<void> {
|
||||
const result = await CoreLoginHelper.openBrowserForOAuthLogin(
|
||||
this.siteUrl,
|
||||
provider,
|
||||
this.siteConfig?.launchurl,
|
||||
|
|
|
@ -34,6 +34,7 @@ import { SafeHtml } from '@angular/platform-browser';
|
|||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreSitesFactory } from '@services/sites-factory';
|
||||
import { EMAIL_SIGNUP_FEATURE_NAME, FORGOTTEN_PASSWORD_FEATURE_NAME } from '@features/login/constants';
|
||||
import { CoreCustomURLSchemes } from '@services/urlschemes';
|
||||
|
||||
/**
|
||||
* Page to enter the user credentials.
|
||||
|
@ -107,8 +108,11 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
|
|||
await this.checkSite();
|
||||
|
||||
if (this.isBrowserSSO && CoreLoginHelper.shouldSkipCredentialsScreenOnSSO()) {
|
||||
const launchedWithTokenURL = await CoreCustomURLSchemes.appLaunchedWithTokenURL();
|
||||
if (!launchedWithTokenURL) {
|
||||
this.openBrowserSSO();
|
||||
}
|
||||
}
|
||||
|
||||
if (CorePlatform.isIOS() && !this.isBrowserSSO) {
|
||||
// Make iOS auto-fill work. The field that isn't focused doesn't get updated, do it manually.
|
||||
|
|
|
@ -318,7 +318,7 @@ export class CoreLoginEmailSignupPage implements OnInit {
|
|||
};
|
||||
|
||||
if (this.siteConfig?.launchurl) {
|
||||
params.redirect = CoreLoginHelper.prepareForSSOLogin(this.site.getURL(), undefined, this.siteConfig.launchurl);
|
||||
params.redirect = await CoreLoginHelper.prepareForSSOLogin(this.site.getURL(), undefined, this.siteConfig.launchurl);
|
||||
}
|
||||
|
||||
// Get the recaptcha response (if needed).
|
||||
|
|
|
@ -613,12 +613,12 @@ export class CoreLoginHelperProvider {
|
|||
* @param redirectData Data of the path/url to open once authenticated. If not defined, site initial page.
|
||||
* @returns True if success, false if error.
|
||||
*/
|
||||
openBrowserForOAuthLogin(
|
||||
async openBrowserForOAuthLogin(
|
||||
siteUrl: string,
|
||||
provider: CoreSiteIdentityProvider,
|
||||
launchUrl?: string,
|
||||
redirectData?: CoreRedirectPayload,
|
||||
): boolean {
|
||||
): Promise<boolean> {
|
||||
launchUrl = launchUrl || siteUrl + '/admin/tool/mobile/launch.php';
|
||||
|
||||
this.logger.debug('openBrowserForOAuthLogin launchUrl:', launchUrl);
|
||||
|
@ -633,7 +633,10 @@ export class CoreLoginHelperProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
const loginUrl = this.prepareForSSOLogin(siteUrl, undefined, launchUrl, redirectData, {
|
||||
const modal = await CoreDomUtils.showModalLoading();
|
||||
|
||||
try {
|
||||
const loginUrl = await this.prepareForSSOLogin(siteUrl, undefined, launchUrl, redirectData, {
|
||||
oauthsso: params.id,
|
||||
});
|
||||
|
||||
|
@ -642,6 +645,13 @@ export class CoreLoginHelperProvider {
|
|||
CoreApp.closeApp();
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
CoreDomUtils.showErrorModalDefault(error, 'Error opening browser');
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -653,14 +663,17 @@ export class CoreLoginHelperProvider {
|
|||
* @param launchUrl The URL to open for SSO. If not defined, default tool mobile launch URL will be used.
|
||||
* @param redirectData Data of the path/url to open once authenticated. If not defined, site initial page.
|
||||
*/
|
||||
openBrowserForSSOLogin(
|
||||
async openBrowserForSSOLogin(
|
||||
siteUrl: string,
|
||||
typeOfLogin: TypeOfLogin,
|
||||
service?: string,
|
||||
launchUrl?: string,
|
||||
redirectData?: CoreRedirectPayload,
|
||||
): void {
|
||||
const loginUrl = this.prepareForSSOLogin(siteUrl, service, launchUrl, redirectData);
|
||||
): Promise<void> {
|
||||
const modal = await CoreDomUtils.showModalLoading();
|
||||
|
||||
try {
|
||||
const loginUrl = await this.prepareForSSOLogin(siteUrl, service, launchUrl, redirectData);
|
||||
|
||||
this.logger.debug('openBrowserForSSOLogin loginUrl:', loginUrl);
|
||||
|
||||
|
@ -673,6 +686,11 @@ export class CoreLoginHelperProvider {
|
|||
CoreUtils.openInBrowser(loginUrl, { showBrowserWarning: false });
|
||||
CoreApp.closeApp();
|
||||
}
|
||||
} catch (error) {
|
||||
CoreDomUtils.showErrorModalDefault(error, 'Error opening browser');
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -779,13 +797,13 @@ export class CoreLoginHelperProvider {
|
|||
* @param urlParams Other params to add to the URL.
|
||||
* @returns Login Url.
|
||||
*/
|
||||
prepareForSSOLogin(
|
||||
async prepareForSSOLogin(
|
||||
siteUrl: string,
|
||||
service?: string,
|
||||
launchUrl?: string,
|
||||
redirectData: CoreRedirectPayload = {},
|
||||
urlParams?: CoreUrlParams,
|
||||
): string {
|
||||
): Promise<string> {
|
||||
|
||||
service = service || CoreConstants.CONFIG.wsservice;
|
||||
launchUrl = launchUrl || siteUrl + '/admin/tool/mobile/launch.php';
|
||||
|
@ -802,7 +820,7 @@ export class CoreLoginHelperProvider {
|
|||
|
||||
// Store the siteurl and passport in CoreConfigProvider for persistence.
|
||||
// We are "configuring" the app to wait for an SSO. CoreConfigProvider shouldn't be used as a temporary storage.
|
||||
CoreConfig.set(CoreConstants.LOGIN_LAUNCH_DATA, JSON.stringify(<StoredLoginLaunchData> {
|
||||
await CoreConfig.set(CoreConstants.LOGIN_LAUNCH_DATA, JSON.stringify(<StoredLoginLaunchData> {
|
||||
siteUrl: siteUrl,
|
||||
passport: passport,
|
||||
...redirectData,
|
||||
|
|
|
@ -502,6 +502,29 @@ export class CoreCustomURLSchemesProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last URL used to open the app using a URL scheme.
|
||||
*
|
||||
* @returns URL.
|
||||
*/
|
||||
getLastLaunchURL(): Promise<string | undefined> {
|
||||
return new Promise((resolve) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(<any> window).plugins.launchmyapp.getLastIntent(intent => resolve(intent), () => resolve(undefined));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the last URL used to open the app was a token URL.
|
||||
*
|
||||
* @returns Whether was launched with token URL.
|
||||
*/
|
||||
async appLaunchedWithTokenURL(): Promise<boolean> {
|
||||
const launchUrl = await this.getLastLaunchURL();
|
||||
|
||||
return !!launchUrl && this.isCustomURLToken(launchUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue