diff --git a/packages/auth/src/app.ts b/packages/auth/src/app.ts index fd969e2521..7118e932d2 100644 --- a/packages/auth/src/app.ts +++ b/packages/auth/src/app.ts @@ -13,7 +13,20 @@ import Router from '@koa/router' import { IAppConfig } from './config/app' import { ClientService } from './client/service' import { GrantService } from './grant/service' -import { AccessTokenRoutes } from './accessToken/routes' +import { + CreateContext, + ContinueContext, + StartContext, + GetContext, + ChooseContext, + FinishContext +} from './grant/routes' +import { + AccessTokenRoutes, + IntrospectContext, + RevokeContext, + RotateContext +} from './accessToken/routes' import { createValidatorMiddleware, HttpMethod } from 'openapi' import { @@ -36,13 +49,6 @@ export interface AppContextData extends DefaultContext { export type AppContext = Koa.ParameterizedContext -type ContextType = T extends ( - ctx: infer Context - // eslint-disable-next-line @typescript-eslint/no-explicit-any -) => any - ? Context - : never - export interface DatabaseCleanupRule { /** * the name of the column containing the starting time from which the age will be computed @@ -209,13 +215,10 @@ export class App { } = grantRoutes this.publicRouter.post( '/', - createValidatorMiddleware>( - openApi.authServerSpec, - { - path: '/', - method: HttpMethod.POST - } - ), + createValidatorMiddleware(openApi.authServerSpec, { + path: '/', + method: HttpMethod.POST + }), this.config.bypassSignatureValidation ? (ctx, next) => next() : grantInitiationHttpsigMiddleware, @@ -225,13 +228,10 @@ export class App { // Grant Continue this.publicRouter.post( '/continue/:id', - createValidatorMiddleware>( - openApi.authServerSpec, - { - path: '/continue/{id}', - method: HttpMethod.POST - } - ), + createValidatorMiddleware(openApi.authServerSpec, { + path: '/continue/{id}', + method: HttpMethod.POST + }), this.config.bypassSignatureValidation ? (ctx, next) => next() : grantContinueHttpsigMiddleware, @@ -250,13 +250,10 @@ export class App { } = accessTokenRoutes this.publicRouter.post( '/token/:id', - createValidatorMiddleware>( - openApi.authServerSpec, - { - path: '/token/{id}', - method: HttpMethod.POST - } - ), + createValidatorMiddleware(openApi.authServerSpec, { + path: '/token/{id}', + method: HttpMethod.POST + }), this.config.bypassSignatureValidation ? (ctx, next) => next() : tokenHttpsigMiddleware, @@ -266,13 +263,10 @@ export class App { // Token Revocation this.publicRouter.delete( '/token/:id', - createValidatorMiddleware>( - openApi.authServerSpec, - { - path: '/token/{id}', - method: HttpMethod.DELETE - } - ), + createValidatorMiddleware(openApi.authServerSpec, { + path: '/token/{id}', + method: HttpMethod.DELETE + }), this.config.bypassSignatureValidation ? (ctx, next) => next() : tokenHttpsigMiddleware, @@ -283,13 +277,10 @@ export class App { // Token Introspection this.publicRouter.post( '/introspect', - createValidatorMiddleware>( - openApi.tokenIntrospectionSpec, - { - path: '/introspect', - method: HttpMethod.POST - } - ), + createValidatorMiddleware(openApi.tokenIntrospectionSpec, { + path: '/introspect', + method: HttpMethod.POST + }), tokenIntrospect ) @@ -311,52 +302,40 @@ export class App { // Interaction start this.publicRouter.get( '/interact/:id/:nonce', - createValidatorMiddleware>( - openApi.idpSpec, - { - path: '/interact/{id}/{nonce}', - method: HttpMethod.GET - } - ), + createValidatorMiddleware(openApi.idpSpec, { + path: '/interact/{id}/{nonce}', + method: HttpMethod.GET + }), interactionStart ) // Interaction finish this.publicRouter.get( '/interact/:id/:nonce/finish', - createValidatorMiddleware>( - openApi.idpSpec, - { - path: '/interact/{id}/{nonce}/finish', - method: HttpMethod.GET - } - ), + createValidatorMiddleware(openApi.idpSpec, { + path: '/interact/{id}/{nonce}/finish', + method: HttpMethod.GET + }), interactionFinish ) // Grant lookup this.publicRouter.get( '/grant/:id/:nonce', - createValidatorMiddleware>( - openApi.idpSpec, - { - path: '/grant/{id}/{nonce}', - method: HttpMethod.GET - } - ), + createValidatorMiddleware(openApi.idpSpec, { + path: '/grant/{id}/{nonce}', + method: HttpMethod.GET + }), interactionDetails ) // Grant accept/reject this.publicRouter.post( '/grant/:id/:nonce/:choice', - createValidatorMiddleware>( - openApi.idpSpec, - { - path: '/grant/{id}/{nonce}/{choice}', - method: HttpMethod.POST - } - ), + createValidatorMiddleware(openApi.idpSpec, { + path: '/grant/{id}/{nonce}/{choice}', + method: HttpMethod.POST + }), interactionAcceptOrReject ) diff --git a/packages/openapi/src/middleware.ts b/packages/openapi/src/middleware.ts index 8ce9fe404f..24a755a317 100644 --- a/packages/openapi/src/middleware.ts +++ b/packages/openapi/src/middleware.ts @@ -2,7 +2,7 @@ import { OpenAPI, RequestOptions, isValidationError } from './' import Koa from 'koa' -export function createValidatorMiddleware( +export function createValidatorMiddleware( spec: OpenAPI, options: RequestOptions ): (ctx: Koa.Context, next: () => Promise) => Promise {