MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / createMethod

Method createMethod

lib/models/multi-factor-auth/totp.ts:160–193  ·  view source on GitHub ↗
(
    id: string,
    name: string,
    issuer: string,
    accountName: string,
  )

Source from the content-addressed store, hash-verified

158 }
159
160 static async createMethod(
161 id: string,
162 name: string,
163 issuer: string,
164 accountName: string,
165 ): Promise<MultiFactorAuthSetup> {
166 const secret = this.generateTOTPSecret();
167 const backupCodes = this.generateBackupCodes();
168 const qrCodeUrl = await this.generateQRCodeDataURL(secret, issuer, accountName);
169
170 const encryptedSecret = await this.encryptTOTPSecret(secret);
171 const hashedBackupCodes = await this.hashBackupCodes(backupCodes);
172
173 const method: MultiFactorAuthMethod = {
174 type: 'totp',
175 id,
176 name,
177 enabled: false,
178 created_at: new Date(),
179 metadata: {
180 totp: {
181 hashed_secret: encryptedSecret,
182 hashed_backup_codes: hashedBackupCodes,
183 },
184 },
185 };
186
187 return {
188 method,
189 qrCodeUrl,
190 plainTextSecret: secret,
191 plainTextBackupCodes: backupCodes,
192 };
193 }
194
195 static async verifyMethodToken(
196 metadata: MultiFactorAuthMethod['metadata'],

Callers 3

postFunction · 0.45
postFunction · 0.45
postFunction · 0.45

Calls 5

generateTOTPSecretMethod · 0.95
generateBackupCodesMethod · 0.95
generateQRCodeDataURLMethod · 0.95
encryptTOTPSecretMethod · 0.95
hashBackupCodesMethod · 0.95

Tested by

no test coverage detected