feat: refactor auth middleware to handle required and optional cross service token scenarios (#612)

* wip: fix variable name

* wip: remove redundant middleware in auth

* fix: auth middleware refactor

* fix(auth): fetching user for key params

* fix(auth): specs

* fix(auth): registering session controller endpoints
This commit is contained in:
Karol Sójko
2023-05-25 09:43:00 +02:00
committed by GitHub
parent ec75795a02
commit 1e4c7d0f31
45 changed files with 296 additions and 473 deletions
@@ -35,9 +35,7 @@ describe('GetUserKeyParams', () => {
})
it('should get key params for an authenticated user - searching by email', async () => {
expect(
await createUseCase().execute({ email: '[email protected]', authenticated: true, authenticatedUser: user }),
).toEqual({
expect(await createUseCase().execute({ email: '[email protected]', authenticated: true })).toEqual({
keyParams: {
foo: 'bar',
},
@@ -63,7 +61,7 @@ describe('GetUserKeyParams', () => {
})
it('should get key params for an authenticated user - searching by uuid', async () => {
expect(await createUseCase().execute({ userUuid: '1-2-3', authenticated: true, authenticatedUser: user })).toEqual({
expect(await createUseCase().execute({ userUuid: '1-2-3', authenticated: true })).toEqual({
keyParams: {
foo: 'bar',
},
@@ -22,16 +22,6 @@ export class GetUserKeyParams implements UseCaseInterface {
) {}
async execute(dto: GetUserKeyParamsDTO): Promise<GetUserKeyParamsResponse> {
if (dto.authenticatedUser) {
this.logger.debug(`Creating key params for authenticated user ${dto.authenticatedUser.email}`)
const keyParams = await this.createKeyParams(dto, dto.authenticatedUser, true)
return {
keyParams,
}
}
let user: User | null = null
if (dto.email !== undefined) {
const usernameOrError = Username.create(dto.email)
@@ -1,8 +1,5 @@
import { User } from '../../User/User'
export type GetUserKeyParamsDTOV1Unchallenged = {
authenticated: boolean
email?: string
userUuid?: string
authenticatedUser?: User
}
@@ -1,9 +1,6 @@
import { User } from '../../User/User'
export type GetUserKeyParamsDTOV2Challenged = {
authenticated: boolean
codeChallenge: string
email?: string
userUuid?: string
authenticatedUser?: User
}