【发布时间】:2021-08-05 00:00:41
【问题描述】:
我正在使用auth0/angular-jwt 库在我的应用程序中注入 JWT 令牌。在库文档中,它指出配置可以通过字符串或 RegExp 来完成,以设置允许的域。但是,在 app.module.ts 导入部分中使用以下配置时
JwtModule.forRoot({
config: {
tokenGetter: tokenGetter,
whitelistedDomains:[new RegExp("([a-z]+)*-api[.]mydomain[.]cl"),new RegExp("localhost[:]8080")]
}
}),
为生产编译的 main.js 文件获取 {tokenGetter:r,whitelistedDomains:[]},因此,由于没有允许的域,因此不会注入令牌。
如果使用字符串作为域,它可以正常工作。编译时
JwtModule.forRoot({
config: {
tokenGetter: tokenGetter,
whitelistedDomains:["demo-api.mydomain.cl"),"localhost:8080"]
}
}),
main.js 配置正确 {tokenGetter:r,whitelistedDomains:["localhost:8080","demo-api.tumunicipio.cl"]}
package.json
"dependencies": {
"@angular/animations": "8.2.2",
"@angular/common": "8.2.2",
"@angular/compiler": "8.2.2",
"@angular/core": "8.2.2",
"@angular/forms": "8.2.2",
"@angular/platform-browser": "8.2.2",
"@angular/platform-browser-dynamic": "8.2.2",
"@angular/platform-server": "8.2.2",
"@angular/router": "8.2.2",
"@auth0/angular-jwt": "^4.2.0",
【问题讨论】: