/// /// 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. /// export interface TwoFactorAuthSettings { maxVerificationFailuresBeforeUserLockout: number; providers: Array; totalAllowedTimeForVerification: number; useSystemTwoFactorAuthSettings: boolean; verificationCodeCheckRateLimit: string; verificationCodeSendRateLimit: string; } export interface TwoFactorAuthSettingsForm extends TwoFactorAuthSettings{ providers: Array; verificationCodeCheckRateLimitEnable: boolean; verificationCodeCheckRateLimitNumber: number; verificationCodeCheckRateLimitTime: number; verificationCodeSendRateLimitEnable: boolean; verificationCodeSendRateLimitNumber: number; verificationCodeSendRateLimitTime: number; } export type TwoFactorAuthProviderConfig = Partial; export type TwoFactorAuthProviderConfigForm = Partial & TwoFactorAuthProviderFormConfig; export interface TotpTwoFactorAuthProviderConfig { providerType: TwoFactorAuthProviderType; issuerName: string; } export interface SmsTwoFactorAuthProviderConfig { providerType: TwoFactorAuthProviderType; smsVerificationMessageTemplate: string; verificationCodeLifetime: number; } export interface EmailTwoFactorAuthProviderConfig { providerType: TwoFactorAuthProviderType; verificationCodeLifetime: number; } export interface TwoFactorAuthProviderFormConfig { enable: boolean; } export enum TwoFactorAuthProviderType{ TOTP = 'TOTP', 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 { configs: {TwoFactorAuthProviderType: TwoFactorAuthAccountConfig}; } export interface TwoFaProviderInfo { type: TwoFactorAuthProviderType; default: boolean; } export interface TwoFactorAuthProviderData { name: string; description: string; } export const twoFactorAuthProvidersData = new Map( [ [ TwoFactorAuthProviderType.TOTP, { name: 'Authentication app', description: 'Use apps like Google Authenticator, Authy, or Duo on your phone to authenticate. It will generate a security code for logging in.' } ], [ TwoFactorAuthProviderType.SMS, { name: 'SMS', description: 'Use your phone to authenticate. We\'ll send you a security code via SMS message when you log in.' } ], [ TwoFactorAuthProviderType.EMAIL, { name: 'Email', description: 'Use a security code sent to your email address to authenticate.' } ], ] );