2022-08-27 08:59:26 +00:00
|
|
|
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
2022-09-15 16:21:05 +00:00
|
|
|
// import * as cors from 'cors';
|
2022-08-27 08:59:26 +00:00
|
|
|
import { AuthMiddleware } from 'src/middleware/auth.middleware';
|
2022-09-01 17:19:08 +00:00
|
|
|
import { CSRFMiddleware } from 'src/middleware/csrf.middleware';
|
|
|
|
import { UserMiddleware } from 'src/middleware/user.middleware';
|
2022-08-27 08:59:26 +00:00
|
|
|
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 {
|
2022-09-15 16:21:05 +00:00
|
|
|
// private corsOpts = cors({ origin: true, credentials: true });
|
|
|
|
|
2022-08-27 08:59:26 +00:00
|
|
|
constructor(private _service: OAuth2Service) {}
|
|
|
|
|
|
|
|
configure(consumer: MiddlewareConsumer) {
|
|
|
|
consumer
|
2022-09-09 15:28:54 +00:00
|
|
|
.apply(
|
|
|
|
CSRFMiddleware,
|
|
|
|
UserMiddleware,
|
|
|
|
AuthMiddleware,
|
|
|
|
ValidateCSRFMiddleware,
|
|
|
|
)
|
2022-08-27 08:59:26 +00:00
|
|
|
.forRoutes('oauth2/authorize');
|
2022-09-15 16:21:05 +00:00
|
|
|
|
|
|
|
// consumer
|
|
|
|
// .apply(this.corsOpts)
|
|
|
|
// .forRoutes('oauth2/token', 'oauth2/introspect', 'oauth2/user');
|
|
|
|
|
|
|
|
consumer.apply(this._service.oauth.express()).forRoutes(OAuth2Controller);
|
2022-08-27 08:59:26 +00:00
|
|
|
}
|
|
|
|
}
|