Files
Automata/packages/cli/src/sso/ssoHelpers.ts
कारतोफ्फेलस्क्रिप्ट™ 000e76e3b4 ci(core): Reduce memory usage in tests (part-2) (no-changelog) (#7671)
This also gets rid of `Db.collection`, which was another source of
circular dependencies.
2023-11-10 15:04:26 +01:00

46 lines
1.5 KiB
TypeScript

import config from '@/config';
import { SettingsRepository } from '@db/repositories/settings.repository';
import type { AuthProviderType } from '@db/entities/AuthIdentity';
import Container from 'typedi';
/**
* Only one authentication method can be active at a time. This function sets the current authentication method
* and saves it to the database.
* SSO methods should only switch to email and then to another method. Email can switch to any method.
* @param authenticationMethod
*/
export async function setCurrentAuthenticationMethod(
authenticationMethod: AuthProviderType,
): Promise<void> {
config.set('userManagement.authenticationMethod', authenticationMethod);
await Container.get(SettingsRepository).save({
key: 'userManagement.authenticationMethod',
value: authenticationMethod,
loadOnStartup: true,
});
}
export function getCurrentAuthenticationMethod(): AuthProviderType {
return config.getEnv('userManagement.authenticationMethod');
}
export function isSamlCurrentAuthenticationMethod(): boolean {
return getCurrentAuthenticationMethod() === 'saml';
}
export function isLdapCurrentAuthenticationMethod(): boolean {
return getCurrentAuthenticationMethod() === 'ldap';
}
export function isEmailCurrentAuthenticationMethod(): boolean {
return getCurrentAuthenticationMethod() === 'email';
}
export function isSsoJustInTimeProvisioningEnabled(): boolean {
return config.getEnv('sso.justInTimeProvisioning');
}
export function doRedirectUsersFromLoginToSsoFlow(): boolean {
return config.getEnv('sso.redirectLoginToSso');
}