feat(snjs): add authenticator use cases (#2145)

* feat(snjs): add authenticator use case

* feat(snjs): add use cases for listing, deleting and verifying authenticators

* fix(snjs): spec for deleting authenticator
This commit is contained in:
Karol Sójko
2023-01-11 11:30:42 +01:00
committed by GitHub
parent 8fe78ecf5f
commit 5864ea84e7
16 changed files with 531 additions and 29 deletions

View File

@@ -1,12 +1,14 @@
import { Username, Uuid } from '@standardnotes/domain-core'
export interface AuthenticatorClientInterface {
list(): Promise<Array<{ id: string; name: string }>>
delete(authenticatorId: string): Promise<boolean>
generateRegistrationOptions(userUuid: string, username: string): Promise<Record<string, unknown> | null>
delete(authenticatorId: Uuid): Promise<boolean>
generateRegistrationOptions(userUuid: Uuid, username: Username): Promise<Record<string, unknown> | null>
verifyRegistrationResponse(
userUuid: string,
userUuid: Uuid,
name: string,
registrationCredential: Record<string, unknown>,
): Promise<boolean>
generateAuthenticationOptions(): Promise<Record<string, unknown> | null>
verifyAuthenticationResponse(userUuid: string, authenticationCredential: Record<string, unknown>): Promise<boolean>
verifyAuthenticationResponse(userUuid: Uuid, authenticationCredential: Record<string, unknown>): Promise<boolean>
}

View File

@@ -1,6 +1,7 @@
/* istanbul ignore file */
import { AuthenticatorApiServiceInterface } from '@standardnotes/api'
import { Username, Uuid } from '@standardnotes/domain-core'
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
import { AbstractService } from '../Service/AbstractService'
@@ -28,9 +29,9 @@ export class AuthenticatorManager extends AbstractService implements Authenticat
}
}
async delete(authenticatorId: string): Promise<boolean> {
async delete(authenticatorId: Uuid): Promise<boolean> {
try {
const result = await this.authenticatorApiService.delete(authenticatorId)
const result = await this.authenticatorApiService.delete(authenticatorId.value)
if (result.data.error) {
return false
@@ -42,9 +43,9 @@ export class AuthenticatorManager extends AbstractService implements Authenticat
}
}
async generateRegistrationOptions(userUuid: string, username: string): Promise<Record<string, unknown> | null> {
async generateRegistrationOptions(userUuid: Uuid, username: Username): Promise<Record<string, unknown> | null> {
try {
const result = await this.authenticatorApiService.generateRegistrationOptions(userUuid, username)
const result = await this.authenticatorApiService.generateRegistrationOptions(userUuid.value, username.value)
if (result.data.error) {
return null
@@ -57,13 +58,13 @@ export class AuthenticatorManager extends AbstractService implements Authenticat
}
async verifyRegistrationResponse(
userUuid: string,
userUuid: Uuid,
name: string,
registrationCredential: Record<string, unknown>,
): Promise<boolean> {
try {
const result = await this.authenticatorApiService.verifyRegistrationResponse(
userUuid,
userUuid.value,
name,
registrationCredential,
)
@@ -93,11 +94,14 @@ export class AuthenticatorManager extends AbstractService implements Authenticat
}
async verifyAuthenticationResponse(
userUuid: string,
userUuid: Uuid,
authenticationCredential: Record<string, unknown>,
): Promise<boolean> {
try {
const result = await this.authenticatorApiService.verifyAuthenticationResponse(userUuid, authenticationCredential)
const result = await this.authenticatorApiService.verifyAuthenticationResponse(
userUuid.value,
authenticationCredential,
)
if (result.data.error) {
return false