这是我的代码:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerCustomOptions, SwaggerModule } from '@nestjs/swagger';
import * as config from 'config';
import * as crypto from 'crypto';
async function bootstrap() {
const serverConfig = config.get('conf');
console.log(`Environment:` + serverConfig.env);
console.log(`Running Port:` + serverConfig.server.port);
const teanat = 'MY_AUTH0_DOMAIN'
const app = await NestFactory.create(AppModule);
const nonce = crypto.randomBytes(16).toString('base64');
const docBuilderConfig = new DocumentBuilder()
.setTitle('Awesome Middleware')
.setDescription('Represents the middleware api services')
.setVersion('1.0')
.addOAuth2(
{
type: 'oauth2',
flows: {
implicit: {
tokenUrl: `${teanat}/oauth/token`,
authorizationUrl: `${teanat}/authorize?audience=${`${teanat}/api/v2/`}&nonce=${nonce}`,
scopes: {} // { openid: openid, ... }
},
},
},
)
.build()
const document = SwaggerModule.createDocument(app, docBuilderConfig);
const swaggerCustomOptions: SwaggerCustomOptions = {
'customSiteTitle': 'Middle Api',
'explorer': true,
'swaggerOptions': {
persistAuthorization: true,
oauth2RedirectUrl: 'http://localhost:4200/',
oauth: {
clientId: 'CLIENT_ID',
}
}
}
SwaggerModule.setup('/', app, document, swaggerCustomOptions);
app.enableCors();
app.use((req, res, next) => {
res.header("X-powered-by", "My Company");
res.header("Server", "My Server");
next();
});
await app.listen(4200);
}
bootstrap();
我像在客户端 Web 应用程序中一样转到登录页面,然后在我重定向到的 URL 婴儿车上返回令牌 (localhost:4200?token_access=MY_YOKEN) 我希望将此令牌注入到控件使用的标头中auth2 具有相同的身份验证名称