Merge pull request #3336 from dpalou/MOBILE-4108
MOBILE-4108 core: Don't call autologin WS for external URLsmain
commit
a878c65b29
|
@ -89,7 +89,7 @@ export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseCompo
|
|||
try {
|
||||
const treated = await CoreContentLinksHelper.handleLink(url);
|
||||
if (!treated) {
|
||||
return CoreSites.getCurrentSite()?.openInBrowserWithAutoLoginIfSameSite(url);
|
||||
return CoreSites.getCurrentSite()?.openInBrowserWithAutoLogin(url);
|
||||
}
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
|
|
|
@ -149,7 +149,7 @@ export class AddonBlockTimelineEventsComponent implements OnChanges {
|
|||
try {
|
||||
const treated = await CoreContentLinksHelper.handleLink(url);
|
||||
if (!treated) {
|
||||
return CoreSites.getRequiredCurrentSite().openInBrowserWithAutoLoginIfSameSite(url);
|
||||
return CoreSites.getRequiredCurrentSite().openInBrowserWithAutoLogin(url);
|
||||
}
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
|
|
|
@ -418,7 +418,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
|
|||
const treated = await CoreContentLinksHelper.handleLink(this.siteAfterSubmit);
|
||||
|
||||
if (!treated) {
|
||||
await this.currentSite.openInBrowserWithAutoLoginIfSameSite(this.siteAfterSubmit);
|
||||
await this.currentSite.openInBrowserWithAutoLogin(this.siteAfterSubmit);
|
||||
}
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
|
|
|
@ -221,7 +221,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
|
|||
}
|
||||
|
||||
// The resource cannot be downloaded, open the activity in browser.
|
||||
await CoreSites.getCurrentSite()?.openInBrowserWithAutoLoginIfSameSite(this.module.url || '');
|
||||
await CoreSites.getCurrentSite()?.openInBrowserWithAutoLogin(this.module.url || '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,9 +151,9 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
|
|||
// Will be displayed in an iframe. Check if we need to auto-login.
|
||||
const currentSite = CoreSites.getCurrentSite();
|
||||
|
||||
if (currentSite?.containsUrl(this.url)) {
|
||||
// Format the URL to add auto-login.
|
||||
this.url = await currentSite.getAutoLoginUrl(this.url!, false);
|
||||
if (currentSite && this.url) {
|
||||
// Format the URL to add auto-login if needed.
|
||||
this.url = await currentSite.getAutoLoginUrl(this.url, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ export class AddonModUrlHelperProvider {
|
|||
const treated = await CoreContentLinksHelper.handleLink(url, undefined, true, true);
|
||||
|
||||
if (!treated) {
|
||||
await CoreSites.getCurrentSite()?.openInBrowserWithAutoLoginIfSameSite(url);
|
||||
await CoreSites.getCurrentSite()?.openInBrowserWithAutoLogin(url);
|
||||
}
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
|
|
|
@ -80,7 +80,7 @@ export class AddonReportInsightsActionLinkHandlerService extends CoreContentLink
|
|||
// Cannot be opened in the app, open in browser.
|
||||
const site = await CoreSites.getSite(siteId);
|
||||
|
||||
await site.openInBrowserWithAutoLoginIfSameSite(forwardUrl);
|
||||
await site.openInBrowserWithAutoLogin(forwardUrl);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1533,13 +1533,14 @@ export class CoreSite {
|
|||
* @param alertMessage If defined, an alert will be shown before opening the browser.
|
||||
* @param options Other options.
|
||||
* @return Promise resolved when done, rejected otherwise.
|
||||
* @deprecated since 4.1. Use openInBrowserWithAutoLogin instead, now it always checks that URL belongs to same site.
|
||||
*/
|
||||
async openInBrowserWithAutoLoginIfSameSite(
|
||||
url: string,
|
||||
alertMessage?: string,
|
||||
options: CoreUtilsOpenInBrowserOptions = {},
|
||||
): Promise<void> {
|
||||
await this.openWithAutoLoginIfSameSite(false, url, options, alertMessage);
|
||||
return this.openInBrowserWithAutoLogin(url, alertMessage, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1563,15 +1564,14 @@ export class CoreSite {
|
|||
* @param options Override default options passed to inappbrowser.
|
||||
* @param alertMessage If defined, an alert will be shown before opening the inappbrowser.
|
||||
* @return Promise resolved when done.
|
||||
* @deprecated since 4.1. Use openInAppWithAutoLogin instead, now it always checks that URL belongs to same site.
|
||||
*/
|
||||
async openInAppWithAutoLoginIfSameSite(
|
||||
url: string,
|
||||
options?: InAppBrowserOptions,
|
||||
alertMessage?: string,
|
||||
): Promise<InAppBrowserObject> {
|
||||
const iabInstance = <InAppBrowserObject> await this.openWithAutoLoginIfSameSite(true, url, options, alertMessage);
|
||||
|
||||
return iabInstance;
|
||||
return this.openInAppWithAutoLogin(url, options, alertMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1623,6 +1623,7 @@ export class CoreSite {
|
|||
* @param options Override default options passed to inappbrowser.
|
||||
* @param alertMessage If defined, an alert will be shown before opening the browser/inappbrowser.
|
||||
* @return Promise resolved when done. Resolve param is returned only if inApp=true.
|
||||
* @deprecated since 4.1. Use openWithAutoLogin instead, now it always checks that URL belongs to same site.
|
||||
*/
|
||||
async openWithAutoLoginIfSameSite(
|
||||
inApp: boolean,
|
||||
|
@ -1630,15 +1631,7 @@ export class CoreSite {
|
|||
options: InAppBrowserOptions & CoreUtilsOpenInBrowserOptions = {},
|
||||
alertMessage?: string,
|
||||
): Promise<InAppBrowserObject | void> {
|
||||
if (this.containsUrl(url)) {
|
||||
return this.openWithAutoLogin(inApp, url, options, alertMessage);
|
||||
} else {
|
||||
if (inApp) {
|
||||
return Promise.resolve(CoreUtils.openInApp(url, options));
|
||||
} else {
|
||||
CoreUtils.openInBrowser(url, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1822,6 +1815,11 @@ export class CoreSite {
|
|||
return url;
|
||||
}
|
||||
|
||||
if (!this.containsUrl(url)) {
|
||||
// URL doesn't belong to the site, don't auto login.
|
||||
return url;
|
||||
}
|
||||
|
||||
if (this.lastAutoLogin > 0) {
|
||||
const timeBetweenRequests = await CoreUtils.ignoreErrors(
|
||||
this.getConfig('tool_mobile_autologinmintimebetweenreq'),
|
||||
|
|
|
@ -45,7 +45,7 @@ export class CoreContextMenuItemComponent implements OnInit, OnDestroy, OnChange
|
|||
@Input() ariaAction?: string; // Aria label to add to iconAction. If not set, it will be equal to content.
|
||||
@Input() href?: string; // Link to go if no action provided.
|
||||
@Input() captureLink?: boolean | string; // Whether the link needs to be captured by the app.
|
||||
@Input() autoLogin?: string; // Whether the link needs to be opened using auto-login.
|
||||
@Input() autoLogin: boolean | string = true; // Whether the link needs to be opened using auto-login.
|
||||
@Input() closeOnClick = true; // Whether to close the popover when the item is clicked.
|
||||
@Input() priority?: number; // Used to sort items. The highest priority, the highest position.
|
||||
@Input() badge?: string; // A badge to show in the item.
|
||||
|
@ -88,7 +88,6 @@ export class CoreContextMenuItemComponent implements OnInit, OnDestroy, OnChange
|
|||
|
||||
// Navigation help if href provided.
|
||||
this.captureLink = this.href && this.captureLink ? this.captureLink : false;
|
||||
this.autoLogin = this.autoLogin || 'check';
|
||||
|
||||
if (!this.destroyed) {
|
||||
this.ctxtMenu.addItem(this);
|
||||
|
|
|
@ -601,7 +601,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo
|
|||
}
|
||||
|
||||
if (openInApp) {
|
||||
site.openInAppWithAutoLoginIfSameSite(url);
|
||||
site.openInAppWithAutoLogin(url);
|
||||
|
||||
if (refreshOnResume && this.refreshContext) {
|
||||
// Refresh the context when the IAB is closed.
|
||||
|
@ -610,7 +610,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo
|
|||
});
|
||||
}
|
||||
} else {
|
||||
site.openInBrowserWithAutoLoginIfSameSite(url, undefined, {
|
||||
site.openInBrowserWithAutoLogin(url, undefined, {
|
||||
showBrowserWarning: !confirmMessage,
|
||||
});
|
||||
|
||||
|
|
|
@ -41,11 +41,7 @@ export class CoreLinkDirective implements OnInit {
|
|||
@Input() href?: string | SafeUrl; // Link URL.
|
||||
@Input() capture?: boolean | string; // If the link needs to be captured by the app.
|
||||
@Input() inApp?: boolean | string; // True to open in embedded browser, false to open in system browser.
|
||||
/* Whether the link should be opened with auto-login. Accepts the following values:
|
||||
"yes" -> Always auto-login.
|
||||
"no" -> Never auto-login.
|
||||
"check" -> Auto-login only if it points to the current site. Default value. */
|
||||
@Input() autoLogin = 'check';
|
||||
@Input() autoLogin: boolean | string = true; // Whether to try to use auto-login. Values yes/no/check are deprecated.
|
||||
@Input() showBrowserWarning = true; // Whether to show a warning before opening browser. Defaults to true.
|
||||
|
||||
protected element: HTMLElement;
|
||||
|
@ -61,8 +57,6 @@ export class CoreLinkDirective implements OnInit {
|
|||
* Function executed when the component is initialized.
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
this.inApp = this.inApp === undefined ? this.inApp : CoreUtils.isTrueOrOne(this.inApp);
|
||||
|
||||
if (this.element.tagName != 'BUTTON' && this.element.tagName != 'A') {
|
||||
this.element.setAttribute('tabindex', '0');
|
||||
this.element.setAttribute('role', 'button');
|
||||
|
@ -184,10 +178,16 @@ export class CoreLinkDirective implements OnInit {
|
|||
* @return Promise resolved when done.
|
||||
*/
|
||||
protected async openExternalLink(href: string, openIn?: string | null): Promise<void> {
|
||||
// It's an external link, we will open with browser. Check if we need to auto-login.
|
||||
// Priority order is: core-link inApp attribute > forceOpenLinksIn setting > data-open-in HTML attribute.
|
||||
const openInApp = this.inApp !== undefined ?
|
||||
CoreUtils.isTrueOrOne(this.inApp) :
|
||||
(CoreConstants.CONFIG.forceOpenLinksIn !== 'browser' &&
|
||||
(CoreConstants.CONFIG.forceOpenLinksIn === 'app' || openIn === 'app'));
|
||||
|
||||
// Check if we need to auto-login.
|
||||
if (!CoreSites.isLoggedIn()) {
|
||||
// Not logged in, cannot auto-login.
|
||||
if (this.inApp) {
|
||||
if (openInApp) {
|
||||
CoreUtils.openInApp(href);
|
||||
} else {
|
||||
CoreUtils.openInBrowser(href, { showBrowserWarning: this.showBrowserWarning });
|
||||
|
@ -221,38 +221,22 @@ export class CoreLinkDirective implements OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.autoLogin == 'yes') {
|
||||
if (this.inApp) {
|
||||
const autoLogin = typeof this.autoLogin === 'boolean' ?
|
||||
this.autoLogin :
|
||||
!CoreUtils.isFalseOrZero(this.autoLogin) && this.autoLogin !== 'no'; // Support deprecated values yes/no/check.
|
||||
|
||||
if (autoLogin) {
|
||||
if (openInApp) {
|
||||
await currentSite.openInAppWithAutoLogin(href);
|
||||
} else {
|
||||
await currentSite.openInBrowserWithAutoLogin(href, undefined, { showBrowserWarning: this.showBrowserWarning });
|
||||
}
|
||||
} else if (this.autoLogin == 'no') {
|
||||
if (this.inApp) {
|
||||
} else {
|
||||
if (openInApp) {
|
||||
CoreUtils.openInApp(href);
|
||||
} else {
|
||||
CoreUtils.openInBrowser(href, { showBrowserWarning: this.showBrowserWarning });
|
||||
}
|
||||
} else {
|
||||
// Priority order is: core-link inApp attribute > forceOpenLinksIn setting > data-open-in HTML attribute.
|
||||
let openInApp = this.inApp;
|
||||
if (this.inApp === undefined) {
|
||||
if (CoreConstants.CONFIG.forceOpenLinksIn == 'browser') {
|
||||
openInApp = false;
|
||||
} else if (CoreConstants.CONFIG.forceOpenLinksIn == 'app' || openIn == 'app') {
|
||||
openInApp = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (openInApp) {
|
||||
await currentSite.openInAppWithAutoLoginIfSameSite(href);
|
||||
} else {
|
||||
await currentSite.openInBrowserWithAutoLoginIfSameSite(
|
||||
href,
|
||||
undefined,
|
||||
{ showBrowserWarning: this.showBrowserWarning },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ export class CoreCourseModuleDefaultHandler implements CoreCourseModuleHandler {
|
|||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
CoreSites.getRequiredCurrentSite().openInBrowserWithAutoLoginIfSameSite(url);
|
||||
CoreSites.getRequiredCurrentSite().openInBrowserWithAutoLogin(url);
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ export class CoreH5PIframeComponent implements OnChanges, OnDestroy {
|
|||
CoreH5PCore.DISPLAY_OPTION_DOWNLOAD + '=0',
|
||||
);
|
||||
|
||||
// Get auto-login URL so the user is automatically authenticated.
|
||||
// Get auto-login URL so the user is automatically authenticated if needed.
|
||||
const url = await this.site.getAutoLoginUrl(src, false);
|
||||
|
||||
// Add the preventredirect param so the user can authenticate.
|
||||
|
|
|
@ -166,7 +166,7 @@ export class CoreMainMenuMorePage implements OnInit, OnDestroy {
|
|||
|
||||
if (!treated) {
|
||||
// Can't handle it, open it in browser.
|
||||
CoreSites.getCurrentSite()?.openInBrowserWithAutoLoginIfSameSite(text);
|
||||
CoreSites.getCurrentSite()?.openInBrowserWithAutoLogin(text);
|
||||
}
|
||||
} else {
|
||||
// It's not a URL, open it in a modal so the user can see it and copy it.
|
||||
|
|
|
@ -28,17 +28,16 @@ export class CoreViewerIframePage implements OnInit {
|
|||
|
||||
title?: string; // Page title.
|
||||
url?: string; // Iframe URL.
|
||||
/* Whether the URL should be open with auto-login. Accepts the following values:
|
||||
"yes" -> Always auto-login.
|
||||
"no" -> Never auto-login.
|
||||
"check" -> Auto-login only if it points to the current site. Default value. */
|
||||
autoLogin?: string;
|
||||
autoLogin?: boolean; // Whether to try to use auto-login.
|
||||
finalUrl?: string;
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.title = CoreNavigator.getRouteParam('title');
|
||||
this.url = CoreNavigator.getRouteParam('url');
|
||||
this.autoLogin = CoreNavigator.getRouteParam('autoLogin') || 'check';
|
||||
const autoLoginParam = CoreNavigator.getRouteParam('autoLogin') ?? true;
|
||||
this.autoLogin = typeof autoLoginParam === 'boolean' ?
|
||||
autoLoginParam :
|
||||
autoLoginParam !== 'no'; // Support deprecated values yes/no/check.
|
||||
|
||||
if (!this.url) {
|
||||
return;
|
||||
|
@ -46,7 +45,7 @@ export class CoreViewerIframePage implements OnInit {
|
|||
|
||||
const currentSite = CoreSites.getCurrentSite();
|
||||
|
||||
if (currentSite && (this.autoLogin == 'yes' || (this.autoLogin == 'check' && currentSite.containsUrl(this.url)))) {
|
||||
if (currentSite && this.autoLogin) {
|
||||
// Format the URL to add auto-login.
|
||||
this.finalUrl = await currentSite.getAutoLoginUrl(this.url, false);
|
||||
} else {
|
||||
|
|
|
@ -510,7 +510,7 @@ export class CoreIframeUtilsProvider {
|
|||
if (!CoreSites.isLoggedIn()) {
|
||||
CoreUtils.openInBrowser(link.href);
|
||||
} else {
|
||||
await CoreSites.getCurrentSite()!.openInBrowserWithAutoLoginIfSameSite(link.href);
|
||||
await CoreSites.getCurrentSite()?.openInBrowserWithAutoLogin(link.href);
|
||||
}
|
||||
} else if (link.target == '_parent' || link.target == '_top' || link.target == '_blank') {
|
||||
// Opening links with _parent, _top or _blank can break the app. We'll open it in InAppBrowser.
|
||||
|
|
|
@ -112,7 +112,7 @@ export class CoreWindow {
|
|||
// Not logged in, cannot auto-login.
|
||||
CoreUtils.openInBrowser(url);
|
||||
} else {
|
||||
await CoreSites.getRequiredCurrentSite().openInBrowserWithAutoLoginIfSameSite(url);
|
||||
await CoreSites.getRequiredCurrentSite().openInBrowserWithAutoLogin(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue