-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2731 from Infisical/feat/totp-authenticator
feat: TOTP authenticator
- Loading branch information
Showing
56 changed files
with
1,619 additions
and
210 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
backend/src/db/migrations/20241112082701_add-totp-support.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Knex } from "knex"; | ||
|
||
import { TableName } from "../schemas"; | ||
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils"; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
if (!(await knex.schema.hasTable(TableName.TotpConfig))) { | ||
await knex.schema.createTable(TableName.TotpConfig, (t) => { | ||
t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
t.uuid("userId").notNullable(); | ||
t.foreign("userId").references("id").inTable(TableName.Users).onDelete("CASCADE"); | ||
t.boolean("isVerified").defaultTo(false).notNullable(); | ||
t.binary("encryptedRecoveryCodes").notNullable(); | ||
t.binary("encryptedSecret").notNullable(); | ||
t.timestamps(true, true, true); | ||
t.unique("userId"); | ||
}); | ||
|
||
await createOnUpdateTrigger(knex, TableName.TotpConfig); | ||
} | ||
|
||
const doesOrgMfaMethodColExist = await knex.schema.hasColumn(TableName.Organization, "selectedMfaMethod"); | ||
await knex.schema.alterTable(TableName.Organization, (t) => { | ||
if (!doesOrgMfaMethodColExist) { | ||
t.string("selectedMfaMethod"); | ||
} | ||
}); | ||
|
||
const doesUserSelectedMfaMethodColExist = await knex.schema.hasColumn(TableName.Users, "selectedMfaMethod"); | ||
await knex.schema.alterTable(TableName.Users, (t) => { | ||
if (!doesUserSelectedMfaMethodColExist) { | ||
t.string("selectedMfaMethod"); | ||
} | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await dropOnUpdateTrigger(knex, TableName.TotpConfig); | ||
await knex.schema.dropTableIfExists(TableName.TotpConfig); | ||
|
||
const doesOrgMfaMethodColExist = await knex.schema.hasColumn(TableName.Organization, "selectedMfaMethod"); | ||
await knex.schema.alterTable(TableName.Organization, (t) => { | ||
if (doesOrgMfaMethodColExist) { | ||
t.dropColumn("selectedMfaMethod"); | ||
} | ||
}); | ||
|
||
const doesUserSelectedMfaMethodColExist = await knex.schema.hasColumn(TableName.Users, "selectedMfaMethod"); | ||
await knex.schema.alterTable(TableName.Users, (t) => { | ||
if (doesUserSelectedMfaMethodColExist) { | ||
t.dropColumn("selectedMfaMethod"); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Code generated by automation script, DO NOT EDIT. | ||
// Automated by pulling database and generating zod schema | ||
// To update. Just run npm run generate:schema | ||
// Written by akhilmhdh. | ||
|
||
import { z } from "zod"; | ||
|
||
import { zodBuffer } from "@app/lib/zod"; | ||
|
||
import { TImmutableDBKeys } from "./models"; | ||
|
||
export const TotpConfigsSchema = z.object({ | ||
id: z.string().uuid(), | ||
userId: z.string().uuid(), | ||
isVerified: z.boolean().default(false), | ||
encryptedRecoveryCodes: zodBuffer, | ||
encryptedSecret: zodBuffer, | ||
createdAt: z.date(), | ||
updatedAt: z.date() | ||
}); | ||
|
||
export type TTotpConfigs = z.infer<typeof TotpConfigsSchema>; | ||
export type TTotpConfigsInsert = Omit<z.input<typeof TotpConfigsSchema>, TImmutableDBKeys>; | ||
export type TTotpConfigsUpdate = Partial<Omit<z.input<typeof TotpConfigsSchema>, TImmutableDBKeys>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.