2022-04-29 18:12:35 +03:00
|
|
|
///
|
|
|
|
|
/// Copyright © 2016-2022 The Thingsboard Authors
|
|
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
2022-04-28 23:03:37 +03:00
|
|
|
export interface TwoFactorAuthSettings {
|
|
|
|
|
maxVerificationFailuresBeforeUserLockout: number;
|
|
|
|
|
providers: Array<TwoFactorAuthProviderConfig>;
|
|
|
|
|
totalAllowedTimeForVerification: number;
|
|
|
|
|
useSystemTwoFactorAuthSettings: boolean;
|
|
|
|
|
verificationCodeCheckRateLimit: string;
|
2022-05-20 17:19:21 +03:00
|
|
|
minVerificationCodeSendPeriod: number;
|
2022-04-28 23:03:37 +03:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 17:21:04 +03:00
|
|
|
export interface TwoFactorAuthSettingsForm extends TwoFactorAuthSettings{
|
|
|
|
|
providers: Array<TwoFactorAuthProviderConfigForm>;
|
|
|
|
|
verificationCodeCheckRateLimitEnable: boolean;
|
|
|
|
|
verificationCodeCheckRateLimitNumber: number;
|
|
|
|
|
verificationCodeCheckRateLimitTime: number;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 17:52:22 +03:00
|
|
|
export type TwoFactorAuthProviderConfig = Partial<TotpTwoFactorAuthProviderConfig | SmsTwoFactorAuthProviderConfig |
|
|
|
|
|
EmailTwoFactorAuthProviderConfig>;
|
2022-04-28 23:03:37 +03:00
|
|
|
|
2022-05-16 17:21:04 +03:00
|
|
|
export type TwoFactorAuthProviderConfigForm = Partial<TotpTwoFactorAuthProviderConfig | SmsTwoFactorAuthProviderConfig |
|
|
|
|
|
EmailTwoFactorAuthProviderConfig> & TwoFactorAuthProviderFormConfig;
|
|
|
|
|
|
2022-04-28 23:03:37 +03:00
|
|
|
export interface TotpTwoFactorAuthProviderConfig {
|
|
|
|
|
providerType: TwoFactorAuthProviderType;
|
|
|
|
|
issuerName: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SmsTwoFactorAuthProviderConfig {
|
|
|
|
|
providerType: TwoFactorAuthProviderType;
|
|
|
|
|
smsVerificationMessageTemplate: string;
|
|
|
|
|
verificationCodeLifetime: number;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 17:52:22 +03:00
|
|
|
export interface EmailTwoFactorAuthProviderConfig {
|
|
|
|
|
providerType: TwoFactorAuthProviderType;
|
|
|
|
|
verificationCodeLifetime: number;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 17:21:04 +03:00
|
|
|
export interface TwoFactorAuthProviderFormConfig {
|
|
|
|
|
enable: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 23:03:37 +03:00
|
|
|
export enum TwoFactorAuthProviderType{
|
|
|
|
|
TOTP = 'TOTP',
|
2022-05-06 17:52:22 +03:00
|
|
|
SMS = 'SMS',
|
|
|
|
|
EMAIL = 'EMAIL'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface GeneralTwoFactorAuthAccountConfig {
|
|
|
|
|
providerType: TwoFactorAuthProviderType;
|
|
|
|
|
useByDefault: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TotpTwoFactorAuthAccountConfig extends GeneralTwoFactorAuthAccountConfig {
|
|
|
|
|
authUrl: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface SmsTwoFactorAuthAccountConfig extends GeneralTwoFactorAuthAccountConfig {
|
|
|
|
|
phoneNumber: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EmailTwoFactorAuthAccountConfig extends GeneralTwoFactorAuthAccountConfig {
|
|
|
|
|
email: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type TwoFactorAuthAccountConfig = TotpTwoFactorAuthAccountConfig | SmsTwoFactorAuthAccountConfig | EmailTwoFactorAuthAccountConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface AccountTwoFaSettings {
|
2022-05-16 17:21:04 +03:00
|
|
|
configs: {TwoFactorAuthProviderType: TwoFactorAuthAccountConfig};
|
2022-04-28 23:03:37 +03:00
|
|
|
}
|
2022-05-16 17:21:04 +03:00
|
|
|
|
|
|
|
|
export interface TwoFaProviderInfo {
|
|
|
|
|
type: TwoFactorAuthProviderType;
|
|
|
|
|
default: boolean;
|
2022-05-18 15:44:42 +03:00
|
|
|
contact?: string;
|
2022-05-20 17:19:21 +03:00
|
|
|
minVerificationCodeSendPeriod?: number;
|
2022-05-16 17:21:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TwoFactorAuthProviderData {
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 15:44:42 +03:00
|
|
|
export interface TwoFactorAuthProviderLoginData extends TwoFactorAuthProviderData {
|
|
|
|
|
icon: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 17:21:04 +03:00
|
|
|
export const twoFactorAuthProvidersData = new Map<TwoFactorAuthProviderType, TwoFactorAuthProviderData>(
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
TwoFactorAuthProviderType.TOTP, {
|
2022-05-17 17:38:30 +03:00
|
|
|
name: 'security.2fa.provider.totp',
|
|
|
|
|
description: 'security.2fa.provider.totp-description'
|
2022-05-16 17:21:04 +03:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
TwoFactorAuthProviderType.SMS, {
|
2022-05-17 17:38:30 +03:00
|
|
|
name: 'security.2fa.provider.sms',
|
|
|
|
|
description: 'security.2fa.provider.sms-description'
|
2022-05-16 17:21:04 +03:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
TwoFactorAuthProviderType.EMAIL, {
|
2022-05-17 17:38:30 +03:00
|
|
|
name: 'security.2fa.provider.email',
|
|
|
|
|
description: 'security.2fa.provider.email-description'
|
2022-05-16 17:21:04 +03:00
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
);
|
2022-05-18 15:44:42 +03:00
|
|
|
|
|
|
|
|
export const twoFactorAuthProvidersLoginData = new Map<TwoFactorAuthProviderType, TwoFactorAuthProviderLoginData>(
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
TwoFactorAuthProviderType.TOTP, {
|
|
|
|
|
name: 'security.2fa.provider.totp',
|
|
|
|
|
description: 'login.totp-auth-description',
|
|
|
|
|
icon: 'mdi:cellphone-key'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
TwoFactorAuthProviderType.SMS, {
|
|
|
|
|
name: 'security.2fa.provider.sms',
|
|
|
|
|
description: 'login.sms-auth-description',
|
|
|
|
|
icon: 'mdi:message-reply-text-outline'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
TwoFactorAuthProviderType.EMAIL, {
|
|
|
|
|
name: 'security.2fa.provider.email',
|
|
|
|
|
description: 'login.email-auth-description',
|
|
|
|
|
icon: 'mdi:email-outline'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
);
|