我已经安装了@ auth0 / angular-jwt软件包,并且在Anular2-jwt中有一个名为AuthHttp的类(它将自动添加Bearer并同样设置为Authorization标头).
我们如何用@ auth0 / angular-jwt实现同样的目标
解决方法
AuthHttp不再是这个模块,但你可以用@ auth0 / angular-jwt实现类似的行为.尝试将此配置添加到您的应用模块:
import { JwtModule } from '@auth0/angular-jwt'; ... export function tokenGetter() { return localStorage.getItem('access_token'); } @NgModule({ ... JwtModule.forRoot({ config: { tokenGetter: tokenGetter,whitelistedDomains: ['http://localhost:8080'],blacklistedRoutes: [],headerName: 'x-auth-token',throwNoTokenError: true,skipWhenExpired: false,authScheme:'name of auth scheme' //default is Bearer } }) .... }) export class AppModule { }
有关详细信息,请参阅here.