Merge pull request #2238 from dpalou/MOBILE-3279

MOBILE-3279 login: Allow disabling identity providers
main
Juan Leyva 2020-01-22 16:22:40 +01:00 committed by GitHub
commit 0d1fd43016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View File

@ -155,9 +155,9 @@ export class CoreLoginCredentialsPage {
this.siteName = CoreConfigConstants.sitename ? CoreConfigConstants.sitename : this.siteConfig.sitename; this.siteName = CoreConfigConstants.sitename ? CoreConfigConstants.sitename : this.siteConfig.sitename;
this.logoUrl = this.siteConfig.logourl || this.siteConfig.compactlogourl; this.logoUrl = this.siteConfig.logourl || this.siteConfig.compactlogourl;
this.authInstructions = this.siteConfig.authinstructions || this.translate.instant('core.login.loginsteps'); this.authInstructions = this.siteConfig.authinstructions || this.translate.instant('core.login.loginsteps');
this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig);
const disabledFeatures = this.loginHelper.getDisabledFeatures(this.siteConfig); const disabledFeatures = this.loginHelper.getDisabledFeatures(this.siteConfig);
this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig, disabledFeatures);
this.canSignup = this.siteConfig.registerauth == 'email' && this.canSignup = this.siteConfig.registerauth == 'email' &&
!this.loginHelper.isEmailSignupDisabled(this.siteConfig, disabledFeatures); !this.loginHelper.isEmailSignupDisabled(this.siteConfig, disabledFeatures);
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(this.siteConfig, disabledFeatures); this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(this.siteConfig, disabledFeatures);

View File

@ -74,8 +74,7 @@ export class CoreLoginReconnectPage {
*/ */
ionViewDidLoad(): void { ionViewDidLoad(): void {
if (this.siteConfig) { if (this.siteConfig) {
this.identityProviders = this.loginHelper.getValidIdentityProviders(this.siteConfig); this.getDataFromConfig(this.siteConfig);
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(this.siteConfig);
} }
this.sitesProvider.getSite(this.siteId).then((site) => { this.sitesProvider.getSite(this.siteId).then((site) => {
@ -100,7 +99,7 @@ export class CoreLoginReconnectPage {
this.logoUrl = config.logourl || config.compactlogourl; this.logoUrl = config.logourl || config.compactlogourl;
} }
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(config); this.getDataFromConfig(this.siteConfig);
}).catch(() => { }).catch(() => {
this.cancel(); this.cancel();
}); });
@ -111,7 +110,18 @@ export class CoreLoginReconnectPage {
// Shouldn't happen. Just leave the view. // Shouldn't happen. Just leave the view.
this.cancel(); this.cancel();
}); });
}
/**
* Get some data (like identity providers) from the site config.
*
* @param config Config to use.
*/
protected getDataFromConfig(config: any): void {
const disabledFeatures = this.loginHelper.getDisabledFeatures(config);
this.identityProviders = this.loginHelper.getValidIdentityProviders(config, disabledFeatures);
this.showForgottenPassword = !this.loginHelper.isForgottenPasswordDisabled(config);
} }
/** /**

View File

@ -430,16 +430,25 @@ export class CoreLoginHelperProvider {
* Get the valid identity providers from a site config. * Get the valid identity providers from a site config.
* *
* @param siteConfig Site's public config. * @param siteConfig Site's public config.
* @param disabledFeatures List of disabled features already treated. If not provided it will be calculated.
* @return Valid identity providers. * @return Valid identity providers.
*/ */
getValidIdentityProviders(siteConfig: any): any[] { getValidIdentityProviders(siteConfig: any, disabledFeatures?: string): any[] {
if (this.isFeatureDisabled('NoDelegate_IdentityProviders', siteConfig, disabledFeatures)) {
// Identity providers are disabled, return an empty list.
return [];
}
const validProviders = [], const validProviders = [],
httpUrl = this.textUtils.concatenatePaths(siteConfig.wwwroot, 'auth/oauth2/'), httpUrl = this.textUtils.concatenatePaths(siteConfig.wwwroot, 'auth/oauth2/'),
httpsUrl = this.textUtils.concatenatePaths(siteConfig.httpswwwroot, 'auth/oauth2/'); httpsUrl = this.textUtils.concatenatePaths(siteConfig.httpswwwroot, 'auth/oauth2/');
if (siteConfig.identityproviders && siteConfig.identityproviders.length) { if (siteConfig.identityproviders && siteConfig.identityproviders.length) {
siteConfig.identityproviders.forEach((provider) => { siteConfig.identityproviders.forEach((provider) => {
if (provider.url && (provider.url.indexOf(httpsUrl) != -1 || provider.url.indexOf(httpUrl) != -1)) { const urlParams = this.urlUtils.extractUrlParams(provider.url);
if (provider.url && (provider.url.indexOf(httpsUrl) != -1 || provider.url.indexOf(httpUrl) != -1) &&
!this.isFeatureDisabled('NoDelegate_IdentityProvider_' + urlParams.id, siteConfig, disabledFeatures)) {
validProviders.push(provider); validProviders.push(provider);
} }
}); });