mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {
|
|
AuthenticationMethod,
|
|
AuthenticationMethodsConfiguration
|
|
} from "../configuration/schema/AuthenticationMethodsConfiguration";
|
|
|
|
function computeIsSingleFactorOnlyMode(
|
|
configuration: AuthenticationMethodsConfiguration): boolean {
|
|
if (!configuration)
|
|
return false;
|
|
|
|
const method: AuthenticationMethod = configuration.default_method;
|
|
if (configuration.default_method == "two_factor")
|
|
return false;
|
|
|
|
if (configuration.per_subdomain_methods) {
|
|
for (const key in configuration.per_subdomain_methods) {
|
|
const method = configuration.per_subdomain_methods[key];
|
|
if (method == "two_factor")
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
export class MethodCalculator {
|
|
static compute(config: AuthenticationMethodsConfiguration, subDomain: string)
|
|
: AuthenticationMethod {
|
|
if (config
|
|
&& config.per_subdomain_methods
|
|
&& subDomain in config.per_subdomain_methods) {
|
|
return config.per_subdomain_methods[subDomain];
|
|
}
|
|
return config.default_method;
|
|
}
|
|
|
|
static isSingleFactorOnlyMode(config: AuthenticationMethodsConfiguration)
|
|
: boolean {
|
|
return computeIsSingleFactorOnlyMode(config);
|
|
}
|
|
} |