2023-02-24 11:37:19 -08:00
|
|
|
import config from '@/config';
|
2023-11-10 06:04:26 -08:00
|
|
|
import { SettingsRepository } from '@db/repositories/settings.repository';
|
2023-04-12 01:59:14 -07:00
|
|
|
import type { AuthProviderType } from '@db/entities/AuthIdentity';
|
2023-11-10 06:04:26 -08:00
|
|
|
import Container from 'typedi';
|
2023-02-24 11:37:19 -08:00
|
|
|
|
2023-03-24 09:46:06 -07:00
|
|
|
/**
|
|
|
|
* 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);
|
2024-02-20 07:34:54 -08:00
|
|
|
await Container.get(SettingsRepository).save(
|
|
|
|
{
|
|
|
|
key: 'userManagement.authenticationMethod',
|
|
|
|
value: authenticationMethod,
|
|
|
|
loadOnStartup: true,
|
|
|
|
},
|
|
|
|
{ transaction: false },
|
|
|
|
);
|
2023-03-24 09:46:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getCurrentAuthenticationMethod(): AuthProviderType {
|
|
|
|
return config.getEnv('userManagement.authenticationMethod');
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:37:19 -08:00
|
|
|
export function isSamlCurrentAuthenticationMethod(): boolean {
|
2023-03-24 09:46:06 -07:00
|
|
|
return getCurrentAuthenticationMethod() === 'saml';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isLdapCurrentAuthenticationMethod(): boolean {
|
|
|
|
return getCurrentAuthenticationMethod() === 'ldap';
|
2023-02-24 11:37:19 -08:00
|
|
|
}
|
|
|
|
|
2023-03-10 10:19:52 -08:00
|
|
|
export function isEmailCurrentAuthenticationMethod(): boolean {
|
2023-03-24 09:46:06 -07:00
|
|
|
return getCurrentAuthenticationMethod() === 'email';
|
2023-03-10 10:19:52 -08:00
|
|
|
}
|
|
|
|
|
2023-02-24 11:37:19 -08:00
|
|
|
export function isSsoJustInTimeProvisioningEnabled(): boolean {
|
|
|
|
return config.getEnv('sso.justInTimeProvisioning');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doRedirectUsersFromLoginToSsoFlow(): boolean {
|
|
|
|
return config.getEnv('sso.redirectLoginToSso');
|
|
|
|
}
|