feat(auth): add http endpoints for authenticators

This commit is contained in:
Karol Sójko
2022-12-29 11:29:23 +01:00
parent 14669df890
commit b6fda901ef
28 changed files with 328 additions and 46 deletions
@@ -0,0 +1,58 @@
import { Request, Response } from 'express'
import { inject } from 'inversify'
import {
BaseHttpController,
controller,
httpGet,
httpPost,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
results,
} from 'inversify-express-utils'
import TYPES from '../../Bootstrap/Types'
import { AuthenticatorsController } from '../../Controller/AuthenticatorsController'
@controller('/authenticators', TYPES.ApiGatewayAuthMiddleware)
export class InversifyExpressAuthenticatorsController extends BaseHttpController {
constructor(@inject(TYPES.AuthenticatorsController) private authenticatorsController: AuthenticatorsController) {
super()
}
@httpGet('/generate-registration-options')
async generateRegistrationOptions(_request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.authenticatorsController.generateRegistrationOptions({
username: response.locals.user.email,
userUuid: response.locals.user.uuid,
})
return this.json(result.data, result.status)
}
@httpPost('/verify-registration')
async verifyRegistration(request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.authenticatorsController.verifyRegistrationResponse({
userUuid: response.locals.user.uuid,
registrationCredential: request.body,
})
return this.json(result.data, result.status)
}
@httpGet('/generate-authentication-options')
async generateAuthenticationOptions(_request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.authenticatorsController.generateAuthenticationOptions({
userUuid: response.locals.user.uuid,
})
return this.json(result.data, result.status)
}
@httpPost('/verify-authentication')
async verifyAuthentication(request: Request, response: Response): Promise<results.JsonResult> {
const result = await this.authenticatorsController.verifyAuthenticationResponse({
userUuid: response.locals.user.uuid,
authenticationCredential: request.body,
})
return this.json(result.data, result.status)
}
}