我已经安装了 @auth0/angular-jwt 包,并且在 Anular2-jwt 中有一个名为 AuthHttp 的类(它将自动添加 Bearer 并也设置到 Authorization header 中)。
我们怎样才能用@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 .
关于angular - 'npm i @auth0/angular-jwt' 中不存在 angular2-jwt 中的 AuthHttp 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51399289/