使用Regexp配置时,JWT令牌未发送到auth0/angular JWT中的allowedDomain或whitel



我正在使用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"]}

软件包.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",

这看起来像是AOT编译的问题。这是关于这个话题的一个有角度的问题。唯一可用的解决方案是:

  • 禁用aot进行编译。不建议
  • 在JwtModule允许的域中使用字符串

最新更新