MOBILE-3039 ios: Fix handling URL scheme in iOS
This commit is contained in:
		
							parent
							
								
									cc6b44db5d
								
							
						
					
					
						commit
						6324e3edf0
					
				| @ -82,6 +82,7 @@ export interface CoreCustomURLSchemesParams { | |||||||
| @Injectable() | @Injectable() | ||||||
| export class CoreCustomURLSchemesProvider { | export class CoreCustomURLSchemesProvider { | ||||||
|     protected logger; |     protected logger; | ||||||
|  |     protected lastUrls = {}; | ||||||
| 
 | 
 | ||||||
|     constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, |     constructor(logger: CoreLoggerProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, | ||||||
|             private loginHelper: CoreLoginHelperProvider, private linksHelper: CoreContentLinksHelperProvider, |             private loginHelper: CoreLoginHelperProvider, private linksHelper: CoreContentLinksHelperProvider, | ||||||
| @ -107,6 +108,15 @@ export class CoreCustomURLSchemesProvider { | |||||||
|             isSSOToken = false, |             isSSOToken = false, | ||||||
|             data: CoreCustomURLSchemesParams; |             data: CoreCustomURLSchemesParams; | ||||||
| 
 | 
 | ||||||
|  |         /* First check that this URL hasn't been treated a few seconds ago. The function that handles custom URL schemes already | ||||||
|  |            does this, but this function is called from other places so we need to handle it in here too. */ | ||||||
|  |         if (this.lastUrls[url] && Date.now() - this.lastUrls[url] < 3000) { | ||||||
|  |             // Function called more than once, stop.
 | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         this.lastUrls[url] = Date.now(); | ||||||
|  | 
 | ||||||
|         // Wait for app to be ready.
 |         // Wait for app to be ready.
 | ||||||
|         return this.initDelegate.ready().then(() => { |         return this.initDelegate.ready().then(() => { | ||||||
|             url = this.textUtils.decodeURIComponent(url); |             url = this.textUtils.decodeURIComponent(url); | ||||||
| @ -115,6 +125,10 @@ export class CoreCustomURLSchemesProvider { | |||||||
|             // Some sites add a # at the end of the URL. If it's there, remove it.
 |             // Some sites add a # at the end of the URL. If it's there, remove it.
 | ||||||
|             url = url.replace(/\/?#?\/?$/, ''); |             url = url.replace(/\/?#?\/?$/, ''); | ||||||
| 
 | 
 | ||||||
|  |             // In iOS, the protocol after the scheme doesn't have ":". Add it.
 | ||||||
|  |             // E.g. "moodlemobile://https://..." is received as "moodlemobile://https//..."
 | ||||||
|  |             url = url.replace(/\/\/(https?)\/\//, '//$1://'); | ||||||
|  | 
 | ||||||
|             modal = this.domUtils.showModalLoading(); |             modal = this.domUtils.showModalLoading(); | ||||||
| 
 | 
 | ||||||
|             // Get the data from the URL.
 |             // Get the data from the URL.
 | ||||||
| @ -268,7 +282,9 @@ export class CoreCustomURLSchemesProvider { | |||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|         }).catch((error) => { |         }).catch((error) => { | ||||||
|             if (error && isSSOToken) { |             if (error == 'Duplicated') { | ||||||
|  |                 // Duplicated request
 | ||||||
|  |             } else if (error && isSSOToken) { | ||||||
|                 // An error occurred, display the error and logout the user.
 |                 // An error occurred, display the error and logout the user.
 | ||||||
|                 this.loginHelper.treatUserTokenError(data.siteUrl, error); |                 this.loginHelper.treatUserTokenError(data.siteUrl, error); | ||||||
|                 this.sitesProvider.logout(); |                 this.sitesProvider.logout(); | ||||||
| @ -426,7 +442,7 @@ export class CoreCustomURLSchemesProvider { | |||||||
| 
 | 
 | ||||||
|         if (this.appProvider.isSSOAuthenticationOngoing()) { |         if (this.appProvider.isSSOAuthenticationOngoing()) { | ||||||
|             // Authentication ongoing, probably duplicated request.
 |             // Authentication ongoing, probably duplicated request.
 | ||||||
|             return Promise.reject(null); |             return Promise.reject('Duplicated'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (this.appProvider.isDesktop()) { |         if (this.appProvider.isDesktop()) { | ||||||
| @ -452,7 +468,7 @@ export class CoreCustomURLSchemesProvider { | |||||||
|             // Error decoding the parameter.
 |             // Error decoding the parameter.
 | ||||||
|             this.logger.error('Error decoding parameter received for login SSO'); |             this.logger.error('Error decoding parameter received for login SSO'); | ||||||
| 
 | 
 | ||||||
|             return null; |             return Promise.reject(null); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return this.loginHelper.validateBrowserSSOLogin(url); |         return this.loginHelper.validateBrowserSSOLogin(url); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user