Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
angular2 jwt中的AuthHttp类在';npm i@auth0/angular jwt';_Angular - Fatal编程技术网

angular2 jwt中的AuthHttp类在';npm i@auth0/angular jwt';

angular2 jwt中的AuthHttp类在';npm i@auth0/angular jwt';,angular,Angular,我已经安装了@auth0/angular jwt包,在Anular2 jwt中有一个名为AuthHttp的类(它将自动添加承载,并将其设置到授权头中) 我们如何使用@auth0/angular jwt实现相同的功能本模块不再介绍AuthHttp,但您可以使用@auth0/angular jwt实现类似的功能。尝试将此配置添加到您的应用程序模块: import { JwtModule } from '@auth0/angular-jwt'; ... export function tokenGe

我已经安装了@auth0/angular jwt包,在Anular2 jwt中有一个名为AuthHttp的类(它将自动添加承载,并将其设置到授权头中)


我们如何使用@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 { }

有关更多详细信息,请参阅。

我在AppModule中添加了以下代码:JwtModule.forRoot({config:{tokenGetter:tokenGetter,whitelistedDomains:[',BlackListedLotes:[]}),并在我的服务中添加了以下代码…构造函数(私有http:http,私有authHttp:HttpClient){}getOrders(){this.authHttp.get('/api/orders').subscribe(data=>console.log(data),err=>console.log(err));}…但是我得到的是404 get 404(找不到),但是当我使用http时,它能够点击订单apiCan您可以尝试为localStorage.setItem('access_token','value')设置一些伪值在服务呼叫之前。将您的服务url添加到
whitelistedDomains:['localhost:4200']
中,希望它不是
localhost:8080
为您服务。您能在stackblitz上共享您的代码吗,实际上它应该可以工作。