fix(snjs): simplify authenticator api for generating options (#2147)
This commit is contained in:
@@ -58,10 +58,7 @@ export class AuthenticatorApiService implements AuthenticatorApiServiceInterface
|
||||
}
|
||||
}
|
||||
|
||||
async generateRegistrationOptions(
|
||||
userUuid: string,
|
||||
username: string,
|
||||
): Promise<GenerateAuthenticatorRegistrationOptionsResponse> {
|
||||
async generateRegistrationOptions(): Promise<GenerateAuthenticatorRegistrationOptionsResponse> {
|
||||
if (this.operationsInProgress.get(AuthenticatorApiOperations.GenerateRegistrationOptions)) {
|
||||
throw new ApiCallError(ErrorMessage.GenericInProgress)
|
||||
}
|
||||
@@ -69,10 +66,7 @@ export class AuthenticatorApiService implements AuthenticatorApiServiceInterface
|
||||
this.operationsInProgress.set(AuthenticatorApiOperations.GenerateRegistrationOptions, true)
|
||||
|
||||
try {
|
||||
const response = await this.authenticatorServer.generateRegistrationOptions({
|
||||
username,
|
||||
userUuid,
|
||||
})
|
||||
const response = await this.authenticatorServer.generateRegistrationOptions()
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
@@ -116,7 +110,7 @@ export class AuthenticatorApiService implements AuthenticatorApiServiceInterface
|
||||
this.operationsInProgress.set(AuthenticatorApiOperations.GenerateAuthenticationOptions, true)
|
||||
|
||||
try {
|
||||
const response = await this.authenticatorServer.generateAuthenticationOptions({})
|
||||
const response = await this.authenticatorServer.generateAuthenticationOptions()
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
|
||||
@@ -10,10 +10,7 @@ import {
|
||||
export interface AuthenticatorApiServiceInterface {
|
||||
list(): Promise<ListAuthenticatorsResponse>
|
||||
delete(authenticatorId: string): Promise<DeleteAuthenticatorResponse>
|
||||
generateRegistrationOptions(
|
||||
userUuid: string,
|
||||
username: string,
|
||||
): Promise<GenerateAuthenticatorRegistrationOptionsResponse>
|
||||
generateRegistrationOptions(): Promise<GenerateAuthenticatorRegistrationOptionsResponse>
|
||||
verifyRegistrationResponse(
|
||||
userUuid: string,
|
||||
name: string,
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export interface GenerateAuthenticatorAuthenticationOptionsRequestParams {
|
||||
[additionalParam: string]: unknown
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export interface GenerateAuthenticatorRegistrationOptionsRequestParams {
|
||||
userUuid: string
|
||||
username: string
|
||||
[additionalParam: string]: unknown
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
export * from './ApiEndpointParam'
|
||||
export * from './Authenticator/DeleteAuthenticatorRequestParams'
|
||||
export * from './Authenticator/GenerateAuthenticatorAuthenticationOptionsRequestParams'
|
||||
export * from './Authenticator/GenerateAuthenticatorRegistrationOptionsRequestParams'
|
||||
export * from './Authenticator/ListAuthenticatorsRequestParams'
|
||||
export * from './Authenticator/VerifyAuthenticatorAuthenticationResponseRequestParams'
|
||||
export * from './Authenticator/VerifyAuthenticatorRegistrationResponseRequestParams'
|
||||
|
||||
@@ -2,9 +2,7 @@ import { HttpServiceInterface } from '../../Http/HttpServiceInterface'
|
||||
import {
|
||||
ListAuthenticatorsRequestParams,
|
||||
DeleteAuthenticatorRequestParams,
|
||||
GenerateAuthenticatorRegistrationOptionsRequestParams,
|
||||
VerifyAuthenticatorRegistrationResponseRequestParams,
|
||||
GenerateAuthenticatorAuthenticationOptionsRequestParams,
|
||||
VerifyAuthenticatorAuthenticationResponseRequestParams,
|
||||
} from '../../Request'
|
||||
import {
|
||||
@@ -33,10 +31,8 @@ export class AuthenticatorServer implements AuthenticatorServerInterface {
|
||||
return response as DeleteAuthenticatorResponse
|
||||
}
|
||||
|
||||
async generateRegistrationOptions(
|
||||
params: GenerateAuthenticatorRegistrationOptionsRequestParams,
|
||||
): Promise<GenerateAuthenticatorRegistrationOptionsResponse> {
|
||||
const response = await this.httpService.get(Paths.v1.generateRegistrationOptions, params)
|
||||
async generateRegistrationOptions(): Promise<GenerateAuthenticatorRegistrationOptionsResponse> {
|
||||
const response = await this.httpService.get(Paths.v1.generateRegistrationOptions)
|
||||
|
||||
return response as GenerateAuthenticatorRegistrationOptionsResponse
|
||||
}
|
||||
@@ -49,10 +45,8 @@ export class AuthenticatorServer implements AuthenticatorServerInterface {
|
||||
return response as VerifyAuthenticatorRegistrationResponseResponse
|
||||
}
|
||||
|
||||
async generateAuthenticationOptions(
|
||||
params: GenerateAuthenticatorAuthenticationOptionsRequestParams,
|
||||
): Promise<GenerateAuthenticatorAuthenticationOptionsResponse> {
|
||||
const response = await this.httpService.get(Paths.v1.generateAuthenticationOptions, params)
|
||||
async generateAuthenticationOptions(): Promise<GenerateAuthenticatorAuthenticationOptionsResponse> {
|
||||
const response = await this.httpService.get(Paths.v1.generateAuthenticationOptions)
|
||||
|
||||
return response as GenerateAuthenticatorAuthenticationOptionsResponse
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import {
|
||||
ListAuthenticatorsRequestParams,
|
||||
DeleteAuthenticatorRequestParams,
|
||||
GenerateAuthenticatorRegistrationOptionsRequestParams,
|
||||
VerifyAuthenticatorRegistrationResponseRequestParams,
|
||||
GenerateAuthenticatorAuthenticationOptionsRequestParams,
|
||||
VerifyAuthenticatorAuthenticationResponseRequestParams,
|
||||
} from '../../Request'
|
||||
import {
|
||||
@@ -18,15 +16,11 @@ import {
|
||||
export interface AuthenticatorServerInterface {
|
||||
list(params: ListAuthenticatorsRequestParams): Promise<ListAuthenticatorsResponse>
|
||||
delete(params: DeleteAuthenticatorRequestParams): Promise<DeleteAuthenticatorResponse>
|
||||
generateRegistrationOptions(
|
||||
params: GenerateAuthenticatorRegistrationOptionsRequestParams,
|
||||
): Promise<GenerateAuthenticatorRegistrationOptionsResponse>
|
||||
generateRegistrationOptions(): Promise<GenerateAuthenticatorRegistrationOptionsResponse>
|
||||
verifyRegistrationResponse(
|
||||
params: VerifyAuthenticatorRegistrationResponseRequestParams,
|
||||
): Promise<VerifyAuthenticatorRegistrationResponseResponse>
|
||||
generateAuthenticationOptions(
|
||||
params: GenerateAuthenticatorAuthenticationOptionsRequestParams,
|
||||
): Promise<GenerateAuthenticatorAuthenticationOptionsResponse>
|
||||
generateAuthenticationOptions(): Promise<GenerateAuthenticatorAuthenticationOptionsResponse>
|
||||
verifyAuthenticationResponse(
|
||||
params: VerifyAuthenticatorAuthenticationResponseRequestParams,
|
||||
): Promise<VerifyAuthenticatorAuthenticationResponseResponse>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Username, Uuid } from '@standardnotes/domain-core'
|
||||
import { Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
export interface AuthenticatorClientInterface {
|
||||
list(): Promise<Array<{ id: string; name: string }>>
|
||||
delete(authenticatorId: Uuid): Promise<boolean>
|
||||
generateRegistrationOptions(userUuid: Uuid, username: Username): Promise<Record<string, unknown> | null>
|
||||
generateRegistrationOptions(): Promise<Record<string, unknown> | null>
|
||||
verifyRegistrationResponse(
|
||||
userUuid: Uuid,
|
||||
name: string,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { AuthenticatorApiServiceInterface } from '@standardnotes/api'
|
||||
import { Username, Uuid } from '@standardnotes/domain-core'
|
||||
import { Uuid } from '@standardnotes/domain-core'
|
||||
|
||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
@@ -43,9 +43,9 @@ export class AuthenticatorManager extends AbstractService implements Authenticat
|
||||
}
|
||||
}
|
||||
|
||||
async generateRegistrationOptions(userUuid: Uuid, username: Username): Promise<Record<string, unknown> | null> {
|
||||
async generateRegistrationOptions(): Promise<Record<string, unknown> | null> {
|
||||
try {
|
||||
const result = await this.authenticatorApiService.generateRegistrationOptions(userUuid.value, username.value)
|
||||
const result = await this.authenticatorApiService.generateRegistrationOptions()
|
||||
|
||||
if (result.data.error) {
|
||||
return null
|
||||
|
||||
@@ -23,7 +23,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: 'invalid',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticatorName',
|
||||
})
|
||||
|
||||
@@ -31,25 +30,11 @@ describe('AddAuthenticator', () => {
|
||||
expect(result.getError()).toBe('Could not generate authenticator registration options: Given value is not a valid uuid: invalid')
|
||||
})
|
||||
|
||||
it('should return error if username is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: '',
|
||||
authenticatorName: 'authenticatorName',
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Could not generate authenticator registration options: Username cannot be empty')
|
||||
})
|
||||
|
||||
it('should return error if authenticatorName is invalid', async () => {
|
||||
const useCase = createUseCase()
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: '',
|
||||
})
|
||||
|
||||
@@ -64,7 +49,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -79,7 +63,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -96,7 +79,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -111,7 +93,7 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -124,7 +106,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
@@ -136,7 +117,6 @@ describe('AddAuthenticator', () => {
|
||||
|
||||
const result = await useCase.execute({
|
||||
userUuid: '00000000-0000-0000-0000-000000000000',
|
||||
username: 'username',
|
||||
authenticatorName: 'authenticator',
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AuthenticatorClientInterface } from '@standardnotes/services'
|
||||
import { Result, UseCaseInterface, Username, Uuid, Validator } from '@standardnotes/domain-core'
|
||||
import { Result, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core'
|
||||
|
||||
import { AddAuthenticatorDTO } from './AddAuthenticatorDTO'
|
||||
|
||||
@@ -24,12 +24,6 @@ export class AddAuthenticator implements UseCaseInterface<void> {
|
||||
}
|
||||
const userUuid = userUuidOrError.getValue()
|
||||
|
||||
const usernameOrError = Username.create(dto.username)
|
||||
if (usernameOrError.isFailed()) {
|
||||
return Result.fail(`Could not generate authenticator registration options: ${usernameOrError.getError()}`)
|
||||
}
|
||||
const username = usernameOrError.getValue()
|
||||
|
||||
const authenticatorNameValidatorResult = Validator.isNotEmpty(dto.authenticatorName)
|
||||
if (authenticatorNameValidatorResult.isFailed()) {
|
||||
return Result.fail(
|
||||
@@ -37,7 +31,7 @@ export class AddAuthenticator implements UseCaseInterface<void> {
|
||||
)
|
||||
}
|
||||
|
||||
const registrationOptions = await this.authenticatorClient.generateRegistrationOptions(userUuid, username)
|
||||
const registrationOptions = await this.authenticatorClient.generateRegistrationOptions()
|
||||
if (registrationOptions === null) {
|
||||
return Result.fail('Could not generate authenticator registration options')
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export interface AddAuthenticatorDTO {
|
||||
userUuid: string
|
||||
username: string
|
||||
authenticatorName: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user