import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; import { AuthMiddleware } from 'src/middleware/auth.middleware'; import { CSRFMiddleware } from 'src/middleware/csrf.middleware'; import { UserMiddleware } from 'src/middleware/user.middleware'; import { ValidateCSRFMiddleware } from 'src/middleware/validate-csrf.middleware'; import { OAuth2Module } from 'src/modules/oauth2/oauth2.module'; import { OAuth2Service } from 'src/modules/oauth2/oauth2.service'; import { UserModule } from 'src/modules/objects/user/user.module'; import { OAuth2Controller } from './oauth2-router.controller'; @Module({ controllers: [OAuth2Controller], imports: [OAuth2Module, UserModule], }) export class OAuth2RouterModule implements NestModule { constructor(private _service: OAuth2Service) {} configure(consumer: MiddlewareConsumer) { consumer.apply(CSRFMiddleware, UserMiddleware).forRoutes(OAuth2Controller); consumer.apply(this._service.oauth.express()).forRoutes('oauth2/*'); consumer .apply(AuthMiddleware, ValidateCSRFMiddleware) .forRoutes('oauth2/authorize'); } }