From f5a28ad584e0e6f96e82bc7d533ef8916b4772ca Mon Sep 17 00:00:00 2001
From: Dani Palou
Date: Mon, 20 Jan 2020 11:06:08 +0100
Subject: [PATCH] MOBILE-2853 login: Hide password in reconnect if OAuth
---
src/classes/site.ts | 28 ++++
.../emulator/providers/local-notifications.ts | 2 +-
src/core/login/pages/reconnect/reconnect.html | 11 +-
src/core/login/pages/reconnect/reconnect.ts | 2 +
src/core/login/providers/helper.ts | 48 +++++--
.../providers/pushnotifications.ts | 14 +-
src/providers/app.ts | 6 +-
src/providers/config.ts | 4 +-
src/providers/cron.ts | 4 +-
src/providers/filepool.ts | 8 +-
src/providers/local-notifications.ts | 16 +--
src/providers/sites.ts | 120 ++++++++++++------
src/providers/urlschemes.ts | 31 +----
13 files changed, 187 insertions(+), 107 deletions(-)
diff --git a/src/classes/site.ts b/src/classes/site.ts
index 18c8127ff..54b2dd294 100644
--- a/src/classes/site.ts
+++ b/src/classes/site.ts
@@ -233,6 +233,7 @@ export class CoreSite {
protected requestQueueTimeout = null;
protected tokenPluginFileWorks: boolean;
protected tokenPluginFileWorksPromise: Promise;
+ protected oauthId: number;
/**
* Create a site.
@@ -404,6 +405,15 @@ export class CoreSite {
return !!this.loggedOut;
}
+ /**
+ * Get OAuth ID.
+ *
+ * @return OAuth ID.
+ */
+ getOAuthId(): number {
+ return this.oauthId;
+ }
+
/**
* Set site info.
*
@@ -444,6 +454,24 @@ export class CoreSite {
this.loggedOut = !!loggedOut;
}
+ /**
+ * Set OAuth ID.
+ *
+ * @param oauth OAuth ID.
+ */
+ setOAuthId(oauthId: number): void {
+ this.oauthId = oauthId;
+ }
+
+ /**
+ * Check if the user authenticated in the site using an OAuth method.
+ *
+ * @return {boolean} Whether the user authenticated in the site using an OAuth method.
+ */
+ isOAuth(): boolean {
+ return this.oauthId != null && typeof this.oauthId != 'undefined';
+ }
+
/**
* Can the user access their private files?
*
diff --git a/src/core/emulator/providers/local-notifications.ts b/src/core/emulator/providers/local-notifications.ts
index b5cbcd1eb..affff2e19 100644
--- a/src/core/emulator/providers/local-notifications.ts
+++ b/src/core/emulator/providers/local-notifications.ts
@@ -565,7 +565,7 @@ export class LocalNotificationsMock extends LocalNotifications {
const notifications = await this.appDB.getAllRecords(this.DESKTOP_NOTIFS_TABLE);
notifications.forEach((notification) => {
notification.trigger = {
- at: new Date(notification.at)
+ at: new Date(notification.at),
};
notification.data = this.textUtils.parseJSON(notification.data);
notification.triggered = !!notification.triggered;
diff --git a/src/core/login/pages/reconnect/reconnect.html b/src/core/login/pages/reconnect/reconnect.html
index 3876f7e76..bfb460784 100644
--- a/src/core/login/pages/reconnect/reconnect.html
+++ b/src/core/login/pages/reconnect/reconnect.html
@@ -29,7 +29,7 @@
{{ 'core.login.reconnectdescription' | translate }}
-
-
diff --git a/src/core/login/pages/reconnect/reconnect.ts b/src/core/login/pages/reconnect/reconnect.ts
index b735b4db5..4f73c3dc2 100644
--- a/src/core/login/pages/reconnect/reconnect.ts
+++ b/src/core/login/pages/reconnect/reconnect.ts
@@ -38,6 +38,7 @@ export class CoreLoginReconnectPage {
site: any;
showForgottenPassword = true;
showSiteAvatar = false;
+ isOAuth = false;
protected infoSiteUrl: string;
protected pageName: string;
@@ -87,6 +88,7 @@ export class CoreLoginReconnectPage {
this.username = site.infos.username;
this.siteUrl = site.infos.siteurl;
this.siteName = site.getSiteName();
+ this.isOAuth = site.isOAuth();
// Show logo instead of avatar if it's a fixed site.
this.showSiteAvatar = this.site.avatar && !this.loginHelper.getFixedSites();
diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts
index b05fa15c9..8fefd913c 100644
--- a/src/core/login/providers/helper.ts
+++ b/src/core/login/providers/helper.ts
@@ -62,6 +62,11 @@ export interface CoreLoginSSOData {
* Params to page to the page.
*/
pageParams?: any;
+
+ /**
+ * Other params added to the login url.
+ */
+ ssoUrlParams?: {[name: string]: any};
}
/**
@@ -180,7 +185,8 @@ export class CoreLoginHelperProvider {
}).then((data) => {
siteData = data;
- return this.handleSSOLoginAuthentication(siteData.siteUrl, siteData.token, siteData.privateToken);
+ return this.handleSSOLoginAuthentication(siteData.siteUrl, siteData.token, siteData.privateToken,
+ this.getOAuthIdFromParams(data.ssoUrlParams));
}).then(() => {
if (siteData.pageName) {
// State defined, go to that state instead of site initial page.
@@ -396,6 +402,16 @@ export class CoreLoginHelperProvider {
return 'core.mainmenu.' + (config && config.tool_mobile_forcelogout == '1' ? 'logout' : 'changesite');
}
+ /**
+ * Get the OAuth ID of some URL params (if it has an OAuth ID).
+ *
+ * @param params Params.
+ * @return OAuth ID.
+ */
+ getOAuthIdFromParams(params: {[name: string]: any}): number {
+ return params && typeof params.oauthsso != 'undefined' ? Number(params.oauthsso) : undefined;
+ }
+
/**
* Get the site policy.
*
@@ -548,11 +564,12 @@ export class CoreLoginHelperProvider {
* @param siteUrl Site's URL.
* @param token User's token.
* @param privateToken User's private token.
+ * @param oauthId OAuth ID. Only if the authentication was using an OAuth method.
* @return Promise resolved when the user is authenticated with the token.
*/
- handleSSOLoginAuthentication(siteUrl: string, token: string, privateToken?: string): Promise {
+ handleSSOLoginAuthentication(siteUrl: string, token: string, privateToken?: string, oauthId?: number): Promise {
// Always create a new site to prevent overriding data if another user credentials were introduced.
- return this.sitesProvider.newSite(siteUrl, token, privateToken);
+ return this.sitesProvider.newSite(siteUrl, token, privateToken, true, oauthId);
}
/**
@@ -778,15 +795,16 @@ export class CoreLoginHelperProvider {
return false;
}
- const service = this.sitesProvider.determineService(siteUrl),
- params = this.urlUtils.extractUrlParams(provider.url);
- let loginUrl = this.prepareForSSOLogin(siteUrl, service, launchUrl, pageName, pageParams);
+ const params = this.urlUtils.extractUrlParams(provider.url);
if (!params.id) {
return false;
}
- loginUrl += '&oauthsso=' + params.id;
+ const service = this.sitesProvider.determineService(siteUrl);
+ const loginUrl = this.prepareForSSOLogin(siteUrl, service, launchUrl, pageName, pageParams, {
+ oauthsso: params.id,
+ });
if (this.appProvider.isLinux()) {
// In Linux desktop app, always use embedded browser.
@@ -924,8 +942,12 @@ export class CoreLoginHelperProvider {
* @param launchUrl The URL to open for SSO. If not defined, local_mobile launch URL will be used.
* @param pageName Name of the page to go once authenticated. If not defined, site initial page.
* @param pageParams Params of the state to go once authenticated.
+ * @param urlParams Other params to add to the URL.
+ * @return Login Url.
*/
- prepareForSSOLogin(siteUrl: string, service?: string, launchUrl?: string, pageName?: string, pageParams?: any): string {
+ prepareForSSOLogin(siteUrl: string, service?: string, launchUrl?: string, pageName?: string, pageParams?: any,
+ urlParams?: {[name: string]: any}): string {
+
service = service || CoreConfigConstants.wsextservice;
launchUrl = launchUrl || siteUrl + '/local/mobile/launch.php';
@@ -935,13 +957,18 @@ export class CoreLoginHelperProvider {
loginUrl += '&passport=' + passport;
loginUrl += '&urlscheme=' + CoreConfigConstants.customurlscheme;
+ if (urlParams) {
+ loginUrl = this.urlUtils.addParamsToUrl(loginUrl, urlParams);
+ }
+
// 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.
this.configProvider.set(CoreConstants.LOGIN_LAUNCH_DATA, JSON.stringify({
siteUrl: siteUrl,
passport: passport,
pageName: pageName || '',
- pageParams: pageParams || {}
+ pageParams: pageParams || {},
+ ssoUrlParams: urlParams || {},
}));
return loginUrl;
@@ -1331,7 +1358,8 @@ export class CoreLoginHelperProvider {
token: params[1],
privateToken: params[2],
pageName: data.pageName,
- pageParams: data.pageParams
+ pageParams: data.pageParams,
+ ssoUrlParams: data.ssoUrlParams,
};
} else {
this.logger.debug('Invalid signature in the URL request yours: ' + params[0] + ' mine: '
diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts
index 7540c08f1..fea3bbc0d 100644
--- a/src/core/pushnotifications/providers/pushnotifications.ts
+++ b/src/core/pushnotifications/providers/pushnotifications.ts
@@ -109,9 +109,9 @@ export class CorePushNotificationsProvider {
{
name: 'number',
type: 'INTEGER'
- }
+ },
],
- primaryKeys: ['siteid', 'addon']
+ primaryKeys: ['siteid', 'addon'],
},
{
name: CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE,
@@ -132,10 +132,10 @@ export class CorePushNotificationsProvider {
{
name: 'info',
type: 'TEXT'
- }
- ]
- }
- ]
+ },
+ ],
+ },
+ ],
};
protected siteSchema: CoreSiteSchema = {
name: 'AddonPushNotificationsProvider', // The name still contains "Addon" for backwards compatibility.
@@ -583,7 +583,7 @@ export class CorePushNotificationsProvider {
siteid: site.id,
siteurl: site.getURL(),
token: site.getToken(),
- info: JSON.stringify(site.getInfo())
+ info: JSON.stringify(site.getInfo()),
});
}
diff --git a/src/providers/app.ts b/src/providers/app.ts
index 32745f52a..7a50ff553 100644
--- a/src/providers/app.ts
+++ b/src/providers/app.ts
@@ -115,9 +115,9 @@ export class CoreAppProvider {
},
{
name: 'version',
- type: 'INTEGER'
- }
- ]
+ type: 'INTEGER',
+ },
+ ],
};
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App,
diff --git a/src/providers/config.ts b/src/providers/config.ts
index d74b0fbf7..709b5ce8e 100644
--- a/src/providers/config.ts
+++ b/src/providers/config.ts
@@ -39,8 +39,8 @@ export class CoreConfigProvider {
},
{
name: 'value'
- }
- ]
+ },
+ ],
},
],
};
diff --git a/src/providers/cron.ts b/src/providers/cron.ts
index 2d5930041..f0b130e9f 100644
--- a/src/providers/cron.ts
+++ b/src/providers/cron.ts
@@ -107,8 +107,8 @@ export class CoreCronDelegate {
{
name: 'value',
type: 'INTEGER'
- }
- ]
+ },
+ ],
},
],
};
diff --git a/src/providers/filepool.ts b/src/providers/filepool.ts
index 8b7db5467..8c51e421f 100644
--- a/src/providers/filepool.ts
+++ b/src/providers/filepool.ts
@@ -274,11 +274,11 @@ export class CoreFilepoolProvider {
{
name: 'links',
type: 'TEXT'
- }
+ },
],
- primaryKeys: ['siteId', 'fileId']
- }
- ]
+ primaryKeys: ['siteId', 'fileId'],
+ },
+ ],
};
protected siteSchema: CoreSiteSchema = {
name: 'CoreFilepoolProvider',
diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts
index ab564c322..78f2ccb08 100644
--- a/src/providers/local-notifications.ts
+++ b/src/providers/local-notifications.ts
@@ -56,8 +56,8 @@ export class CoreLocalNotificationsProvider {
name: 'code',
type: 'INTEGER',
notNull: true
- }
- ]
+ },
+ ],
},
{
name: this.COMPONENTS_TABLE,
@@ -71,8 +71,8 @@ export class CoreLocalNotificationsProvider {
name: 'code',
type: 'INTEGER',
notNull: true
- }
- ]
+ },
+ ],
},
{
name: this.TRIGGERED_TABLE,
@@ -86,10 +86,10 @@ export class CoreLocalNotificationsProvider {
name: 'at',
type: 'INTEGER',
notNull: true
- }
- ]
- }
- ]
+ },
+ ],
+ },
+ ],
};
protected logger;
diff --git a/src/providers/sites.ts b/src/providers/sites.ts
index b35aca68e..dca1e4968 100644
--- a/src/providers/sites.ts
+++ b/src/providers/sites.ts
@@ -170,7 +170,7 @@ export const enum CoreSitesReadingStrategy {
* their own database tables. Example:
*
* constructor(sitesProvider: CoreSitesProvider) {
- * this.sitesProvider.registerSiteSchema(this.siteSchema);
+ * this.sitesProvider.registerSiteSchema(this.tableSchema);
*
* This provider will automatically create the tables in the databases of all the instantiated sites, and also to the
* databases of sites instantiated from now on.
@@ -178,15 +178,15 @@ export const enum CoreSitesReadingStrategy {
@Injectable()
export class CoreSitesProvider {
// Variables for the database.
- protected SITES_TABLE = 'sites';
- protected CURRENT_SITE_TABLE = 'current_site';
- protected SCHEMA_VERSIONS_TABLE = 'schema_versions';
+ static SITES_TABLE = 'sites_2';
+ static CURRENT_SITE_TABLE = 'current_site';
+ static SCHEMA_VERSIONS_TABLE = 'schema_versions';
protected appTablesSchema: CoreAppSchema = {
name: 'CoreSitesProvider',
- version: 1,
+ version: 2,
tables: [
{
- name: this.SITES_TABLE,
+ name: CoreSitesProvider.SITES_TABLE,
columns: [
{
name: 'id',
@@ -217,11 +217,15 @@ export class CoreSitesProvider {
{
name: 'loggedOut',
type: 'INTEGER'
- }
- ]
+ },
+ {
+ name: 'oauthId',
+ type: 'INTEGER'
+ },
+ ],
},
{
- name: this.CURRENT_SITE_TABLE,
+ name: CoreSitesProvider.CURRENT_SITE_TABLE,
columns: [
{
name: 'id',
@@ -233,10 +237,36 @@ export class CoreSitesProvider {
type: 'TEXT',
notNull: true,
unique: true
- }
- ]
+ },
+ ],
+ },
+ ],
+ async migrate(db: SQLiteDB, oldVersion: number): Promise {
+ if (oldVersion < 2) {
+ const newTable = CoreSitesProvider.SITES_TABLE;
+ const oldTable = 'sites';
+
+ try {
+ // Check if V1 table exists.
+ await db.tableExists(oldTable);
+
+ // Move the records from the old table.
+ const sites = await db.getAllRecords(oldTable);
+ const promises = [];
+
+ sites.forEach((site) => {
+ promises.push(db.insertRecord(newTable, site));
+ });
+
+ await Promise.all(promises);
+
+ // Data moved, drop the old table.
+ await db.dropTable(oldTable);
+ } catch (error) {
+ // Old table does not exist, ignore.
+ }
}
- ]
+ },
};
// Constants to validate a site version.
@@ -260,7 +290,7 @@ export class CoreSitesProvider {
protected siteSchemas: { [name: string]: CoreSiteSchema } = {};
protected siteTablesSchemas: SQLiteDBTableSchema[] = [
{
- name: this.SCHEMA_VERSIONS_TABLE,
+ name: CoreSitesProvider.SCHEMA_VERSIONS_TABLE,
columns: [
{
name: 'name',
@@ -607,16 +637,17 @@ export class CoreSitesProvider {
* @param token User's token.
* @param privateToken User's private token.
* @param login Whether to login the user in the site. Defaults to true.
+ * @param oauthId OAuth ID. Only if the authentication was using an OAuth method.
* @return A promise resolved with siteId when the site is added and the user is authenticated.
*/
- newSite(siteUrl: string, token: string, privateToken: string = '', login: boolean = true): Promise {
+ newSite(siteUrl: string, token: string, privateToken: string = '', login: boolean = true, oauthId?: number): Promise {
if (typeof login != 'boolean') {
login = true;
}
// Create a "candidate" site to fetch the site info.
- let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken),
- isNewSite = true;
+ let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken, undefined, undefined);
+ let isNewSite = true;
return candidateSite.fetchSiteInfo().then((info) => {
const result = this.isValidMoodleVersion(info);
@@ -634,12 +665,14 @@ export class CoreSitesProvider {
candidateSite.setToken(token);
candidateSite.setPrivateToken(privateToken);
candidateSite.setInfo(info);
+ candidateSite.setOAuthId(oauthId);
} else {
// New site, set site ID and info.
isNewSite = true;
candidateSite.setId(siteId);
candidateSite.setInfo(info);
+ candidateSite.setOAuthId(oauthId);
// Create database tables before login and before any WS call.
return this.migrateSiteSchemas(candidateSite);
@@ -659,7 +692,7 @@ export class CoreSitesProvider {
}
// Add site to sites list.
- this.addSite(siteId, siteUrl, token, info, privateToken, config);
+ this.addSite(siteId, siteUrl, token, info, privateToken, config, oauthId);
this.sites[siteId] = candidateSite;
if (login) {
@@ -864,9 +897,11 @@ export class CoreSitesProvider {
* @param info Site's info.
* @param privateToken User's private token.
* @param config Site config (from tool_mobile_get_config).
+ * @param oauthId OAuth ID. Only if the authentication was using an OAuth method.
* @return Promise resolved when done.
*/
- async addSite(id: string, siteUrl: string, token: string, info: any, privateToken: string = '', config?: any): Promise {
+ async addSite(id: string, siteUrl: string, token: string, info: any, privateToken: string = '', config?: any,
+ oauthId?: number): Promise {
await this.dbReady;
const entry = {
@@ -876,10 +911,11 @@ export class CoreSitesProvider {
info: info ? JSON.stringify(info) : info,
privateToken: privateToken,
config: config ? JSON.stringify(config) : config,
- loggedOut: 0
+ loggedOut: 0,
+ oauthId: oauthId,
};
- return this.appDB.insertRecord(this.SITES_TABLE, entry);
+ return this.appDB.insertRecord(CoreSitesProvider.SITES_TABLE, entry);
}
/**
@@ -1096,7 +1132,7 @@ export class CoreSitesProvider {
delete this.sites[siteId];
try {
- await this.appDB.deleteRecords(this.SITES_TABLE, { id: siteId });
+ await this.appDB.deleteRecords(CoreSitesProvider.SITES_TABLE, { id: siteId });
} catch (err) {
// DB remove shouldn't fail, but we'll go ahead even if it does.
}
@@ -1115,7 +1151,7 @@ export class CoreSitesProvider {
async hasSites(): Promise {
await this.dbReady;
- const count = await this.appDB.countRecords(this.SITES_TABLE);
+ const count = await this.appDB.countRecords(CoreSitesProvider.SITES_TABLE);
return count > 0;
}
@@ -1141,7 +1177,7 @@ export class CoreSitesProvider {
return this.sites[siteId];
} else {
// Retrieve and create the site.
- const data = await this.appDB.getRecord(this.SITES_TABLE, { id: siteId });
+ const data = await this.appDB.getRecord(CoreSitesProvider.SITES_TABLE, { id: siteId });
return this.makeSiteFromSiteListEntry(data);
}
@@ -1164,6 +1200,7 @@ export class CoreSitesProvider {
site = this.sitesFactory.makeSite(entry.id, entry.siteUrl, entry.token,
info, entry.privateToken, config, entry.loggedOut == 1);
+ site.setOAuthId(entry.oauthId);
return this.migrateSiteSchemas(site).then(() => {
// Set site after migrating schemas, or a call to getSite could get the site while tables are being created.
@@ -1222,20 +1259,20 @@ export class CoreSitesProvider {
async getSites(ids?: string[]): Promise {
await this.dbReady;
- const sites = await this.appDB.getAllRecords(this.SITES_TABLE);
+ const sites = await this.appDB.getAllRecords(CoreSitesProvider.SITES_TABLE);
const formattedSites = [];
sites.forEach((site) => {
if (!ids || ids.indexOf(site.id) > -1) {
// Parse info.
- const siteInfo = site.info ? this.textUtils.parseJSON(site.info) : site.info,
- basicInfo: CoreSiteBasicInfo = {
+ const siteInfo = site.info ? this.textUtils.parseJSON(site.info) : site.info;
+ const basicInfo: CoreSiteBasicInfo = {
id: site.id,
siteUrl: site.siteUrl,
fullName: siteInfo && siteInfo.fullname,
siteName: CoreConfigConstants.sitename ? CoreConfigConstants.sitename : siteInfo && siteInfo.sitename,
avatar: siteInfo && siteInfo.userpictureurl,
- siteHomeId: siteInfo && siteInfo.siteid || 1
+ siteHomeId: siteInfo && siteInfo.siteid || 1,
};
formattedSites.push(basicInfo);
}
@@ -1282,7 +1319,7 @@ export class CoreSitesProvider {
async getLoggedInSitesIds(): Promise {
await this.dbReady;
- const sites = await this.appDB.getRecords(this.SITES_TABLE, {loggedOut : 0});
+ const sites = await this.appDB.getRecords(CoreSitesProvider.SITES_TABLE, {loggedOut : 0});
return sites.map((site) => {
return site.id;
@@ -1297,7 +1334,7 @@ export class CoreSitesProvider {
async getSitesIds(): Promise {
await this.dbReady;
- const sites = await this.appDB.getAllRecords(this.SITES_TABLE);
+ const sites = await this.appDB.getAllRecords(CoreSitesProvider.SITES_TABLE);
return sites.map((site) => {
return site.id;
@@ -1318,7 +1355,7 @@ export class CoreSitesProvider {
siteId: siteId
};
- await this.appDB.insertRecord(this.CURRENT_SITE_TABLE, entry);
+ await this.appDB.insertRecord(CoreSitesProvider.CURRENT_SITE_TABLE, entry);
this.eventsProvider.trigger(CoreEventsProvider.LOGIN, {}, siteId);
}
@@ -1344,7 +1381,7 @@ export class CoreSitesProvider {
promises.push(this.setSiteLoggedOut(siteId, true));
}
- promises.push(this.appDB.deleteRecords(this.CURRENT_SITE_TABLE, { id: 1 }));
+ promises.push(this.appDB.deleteRecords(CoreSitesProvider.CURRENT_SITE_TABLE, { id: 1 }));
}
try {
@@ -1369,7 +1406,7 @@ export class CoreSitesProvider {
this.sessionRestored = true;
try {
- const currentSite = await this.appDB.getRecord(this.CURRENT_SITE_TABLE, { id: 1 });
+ const currentSite = await this.appDB.getRecord(CoreSitesProvider.CURRENT_SITE_TABLE, { id: 1 });
const siteId = currentSite.siteId;
this.logger.debug(`Restore session in site ${siteId}`);
@@ -1397,7 +1434,7 @@ export class CoreSitesProvider {
site.setLoggedOut(loggedOut);
- return this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId });
+ return this.appDB.updateRecords(CoreSitesProvider.SITES_TABLE, newValues, { id: siteId });
}
/**
@@ -1439,14 +1476,14 @@ export class CoreSitesProvider {
const newValues = {
token: token,
privateToken: privateToken,
- loggedOut: 0
+ loggedOut: 0,
};
site.token = token;
site.privateToken = privateToken;
site.setLoggedOut(false); // Token updated means the user authenticated again, not logged out anymore.
- return this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId });
+ return this.appDB.updateRecords(CoreSitesProvider.SITES_TABLE, newValues, { id: siteId });
}
/**
@@ -1482,7 +1519,7 @@ export class CoreSitesProvider {
const newValues: any = {
info: JSON.stringify(info),
- loggedOut: site.isLoggedOut() ? 1 : 0
+ loggedOut: site.isLoggedOut() ? 1 : 0,
};
if (typeof config != 'undefined') {
@@ -1491,7 +1528,7 @@ export class CoreSitesProvider {
}
try {
- await this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId });
+ await this.appDB.updateRecords(CoreSitesProvider.SITES_TABLE, newValues, { id: siteId });
} finally {
this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, info, siteId);
}
@@ -1550,7 +1587,7 @@ export class CoreSitesProvider {
}
try {
- const siteEntries = await this.appDB.getAllRecords(this.SITES_TABLE);
+ const siteEntries = await this.appDB.getAllRecords(CoreSitesProvider.SITES_TABLE);
const ids = [];
const promises = [];
@@ -1583,7 +1620,7 @@ export class CoreSitesProvider {
async getStoredCurrentSiteId(): Promise {
await this.dbReady;
- const currentSite = await this.appDB.getRecord(this.CURRENT_SITE_TABLE, { id: 1 });
+ const currentSite = await this.appDB.getRecord(CoreSitesProvider.CURRENT_SITE_TABLE, { id: 1 });
return currentSite.siteId;
}
@@ -1731,7 +1768,7 @@ export class CoreSitesProvider {
const db = site.getDb();
// Fetch installed versions of the schema.
- return db.getAllRecords(this.SCHEMA_VERSIONS_TABLE).then((records) => {
+ return db.getAllRecords(CoreSitesProvider.SCHEMA_VERSIONS_TABLE).then((records) => {
const versions = {};
records.forEach((record) => {
versions[record.name] = record.version;
@@ -1756,7 +1793,8 @@ export class CoreSitesProvider {
}
// Set installed version.
- promise = promise.then(() => db.insertRecord(this.SCHEMA_VERSIONS_TABLE, {name, version: schema.version}));
+ promise = promise.then(() => db.insertRecord(CoreSitesProvider.SCHEMA_VERSIONS_TABLE,
+ {name, version: schema.version}));
promises.push(promise);
}
diff --git a/src/providers/urlschemes.ts b/src/providers/urlschemes.ts
index 9b8fe5e76..b7ed851c3 100644
--- a/src/providers/urlschemes.ts
+++ b/src/providers/urlschemes.ts
@@ -22,7 +22,7 @@ import { CoreDomUtilsProvider } from './utils/dom';
import { CoreTextUtilsProvider } from './utils/text';
import { CoreUrlUtilsProvider } from './utils/url';
import { CoreUtilsProvider } from './utils/utils';
-import { CoreLoginHelperProvider } from '@core/login/providers/helper';
+import { CoreLoginHelperProvider, CoreLoginSSOData } from '@core/login/providers/helper';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins';
@@ -32,21 +32,7 @@ import { CoreConstants } from '@core/constants';
/**
* All params that can be in a custom URL scheme.
*/
-export interface CoreCustomURLSchemesParams {
- /**
- * The site's URL.
- */
- siteUrl: string;
-
- /**
- * User's token. If set, user will be authenticated.
- */
- token?: string;
-
- /**
- * User's private token.
- */
- privateToken?: string;
+export interface CoreCustomURLSchemesParams extends CoreLoginSSOData {
/**
* Username.
@@ -57,16 +43,6 @@ export interface CoreCustomURLSchemesParams {
* URL to open once authenticated.
*/
redirect?: any;
-
- /**
- * Name of the page to go once authenticated.
- */
- pageName?: string;
-
- /**
- * Params to pass to the page.
- */
- pageParams?: any;
}
/*
@@ -162,7 +138,8 @@ export class CoreCustomURLSchemesProvider {
}
return promise.then(() => {
- return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken, isSSOToken);
+ return this.sitesProvider.newSite(data.siteUrl, data.token, data.privateToken, isSSOToken,
+ this.loginHelper.getOAuthIdFromParams(data.ssoUrlParams));
});
} else {
// Token belongs to current site, no need to create it.