mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
feat(auth): add authenticators model
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class addAuthenticators1672223738686 implements MigrationInterface {
|
||||
name = 'addAuthenticators1672223738686'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
'CREATE TABLE `authenticators` (`uuid` varchar(36) NOT NULL, `user_uuid` varchar(36) NOT NULL, `credential_id` text NOT NULL, `credential_public_key` blob NOT NULL, `counter` bigint NOT NULL, `credential_device_type` varchar(32) NOT NULL, `credential_backed_up` tinyint NOT NULL, `transports` varchar(255) NULL, `created_at` bigint NOT NULL, `updated_at` bigint NOT NULL, UNIQUE INDEX `credential_id` (`credential_id`), PRIMARY KEY (`uuid`)) ENGINE=InnoDB',
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query('DROP INDEX `credential_id` ON `authenticators`')
|
||||
await queryRunner.query('DROP TABLE `authenticators`')
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import { SharedSubscriptionInvitation } from '../Domain/SharedSubscription/Share
|
||||
import { OfflineUserSubscription } from '../Domain/Subscription/OfflineUserSubscription'
|
||||
import { UserSubscription } from '../Domain/Subscription/UserSubscription'
|
||||
import { User } from '../Domain/User/User'
|
||||
import { TypeORMAuthenticator } from '../Infra/TypeORM/TypeORMAuthenticator'
|
||||
import { TypeORMSessionTrace } from '../Infra/TypeORM/TypeORMSessionTrace'
|
||||
import { Env } from './Env'
|
||||
|
||||
@@ -58,6 +59,7 @@ export const AppDataSource = new DataSource({
|
||||
SharedSubscriptionInvitation,
|
||||
SubscriptionSetting,
|
||||
TypeORMSessionTrace,
|
||||
TypeORMAuthenticator,
|
||||
],
|
||||
migrations: [env.get('DB_MIGRATIONS_PATH', true) ?? 'dist/migrations/*.js'],
|
||||
migrationsRun: true,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Entity, Result, UniqueEntityId } from '@standardnotes/domain-core'
|
||||
|
||||
import { AuthenticatorProps } from './AuthenticatorProps'
|
||||
|
||||
export class Authenticator extends Entity<AuthenticatorProps> {
|
||||
get id(): UniqueEntityId {
|
||||
return this._id
|
||||
}
|
||||
|
||||
private constructor(props: AuthenticatorProps, id?: UniqueEntityId) {
|
||||
super(props, id)
|
||||
}
|
||||
|
||||
static create(props: AuthenticatorProps, id?: UniqueEntityId): Result<Authenticator> {
|
||||
return Result.ok<Authenticator>(new Authenticator(props, id))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export interface AuthenticatorProps {
|
||||
credentialId: Buffer
|
||||
credentialPublicKey: Buffer
|
||||
counter: number
|
||||
credentialDeviceType: string
|
||||
credentialBackedUp: boolean
|
||||
transports?: string[]
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm'
|
||||
|
||||
@Entity({ name: 'authenticators' })
|
||||
export class TypeORMAuthenticator {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
declare uuid: string
|
||||
|
||||
@Column({
|
||||
name: 'user_uuid',
|
||||
length: 36,
|
||||
})
|
||||
declare userUuid: string
|
||||
|
||||
@Column({
|
||||
name: 'credential_id',
|
||||
type: 'text',
|
||||
})
|
||||
@Index('credential_id', { unique: true })
|
||||
declare credentialId: Buffer
|
||||
|
||||
@Column({
|
||||
name: 'credential_public_key',
|
||||
type: 'blob',
|
||||
})
|
||||
declare credentialPublicKey: Buffer
|
||||
|
||||
@Column({
|
||||
name: 'counter',
|
||||
type: 'bigint',
|
||||
})
|
||||
declare counter: number
|
||||
|
||||
@Column({
|
||||
name: 'credential_device_type',
|
||||
type: 'varchar',
|
||||
length: 32,
|
||||
})
|
||||
declare credentialDeviceType: string
|
||||
|
||||
@Column({
|
||||
name: 'credential_backed_up',
|
||||
})
|
||||
declare credentialBackedUp: boolean
|
||||
|
||||
@Column({
|
||||
name: 'transports',
|
||||
type: 'varchar',
|
||||
length: 255,
|
||||
nullable: true,
|
||||
})
|
||||
declare transports: string[]
|
||||
|
||||
@Column({
|
||||
name: 'created_at',
|
||||
type: 'bigint',
|
||||
})
|
||||
declare createdAt: number
|
||||
|
||||
@Column({
|
||||
name: 'updated_at',
|
||||
type: 'bigint',
|
||||
})
|
||||
declare updatedAt: number
|
||||
}
|
||||
Reference in New Issue
Block a user