feat(auth): add verifying authenticator registration response

This commit is contained in:
Karol Sójko
2022-12-28 15:50:48 +01:00
parent 0a420ce30e
commit f5683cfd94
11 changed files with 319 additions and 6 deletions
@@ -1,4 +1,4 @@
import { MapperInterface } from '@standardnotes/domain-core'
import { MapperInterface, Uuid } from '@standardnotes/domain-core'
import { Repository } from 'typeorm'
import { AuthenticatorChallenge } from '../../Domain/Authenticator/AuthenticatorChallenge'
@@ -12,6 +12,22 @@ export class MySQLAuthenticatorChallengeRepository implements AuthenticatorChall
private mapper: MapperInterface<AuthenticatorChallenge, TypeORMAuthenticatorChallenge>,
) {}
async findByUserUuidAndChallenge(userUuid: Uuid, challenge: Buffer): Promise<AuthenticatorChallenge | null> {
const typeOrm = await this.ormRepository
.createQueryBuilder('challenge')
.where('challenge.user_uuid = :userUuid and challenge.challenge = :challenge', {
userUuid: userUuid.value,
challenge,
})
.getOne()
if (typeOrm === null) {
return null
}
return this.mapper.toDomain(typeOrm)
}
async save(authenticatorChallenge: AuthenticatorChallenge): Promise<void> {
const persistence = this.mapper.toProjection(authenticatorChallenge)
@@ -11,6 +11,12 @@ export class MySQLAuthenticatorRepository implements AuthenticatorRepositoryInte
private mapper: MapperInterface<Authenticator, TypeORMAuthenticator>,
) {}
async save(authenticator: Authenticator): Promise<void> {
const persistence = this.mapper.toProjection(authenticator)
await this.ormRepository.save(persistence)
}
async findByUserUuid(userUuid: Uuid): Promise<Authenticator[]> {
const typeOrm = await this.ormRepository
.createQueryBuilder('authenticator')