2024-09-12 09:07:18 -07:00
|
|
|
import Container from 'typedi';
|
|
|
|
|
2023-02-24 11:37:19 -08:00
|
|
|
import config from '@/config';
|
2024-08-27 07:44:32 -07:00
|
|
|
import type { AuthProviderType } from '@/databases/entities/auth-identity';
|
2024-09-12 09:07:18 -07:00
|
|
|
import { SettingsRepository } from '@/databases/repositories/settings.repository';
|
2023-02-24 11:37:19 -08:00
|
|
|
|
2023-03-24 09:46:06 -07:00
|
|
|
/**
|
2024-11-07 05:16:47 -08: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.
|
2023-03-24 09:46:06 -07:00
|
|
|
*/
|
|
|
|
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');
|
|
|
|
}
|