简体   繁体   中英

AuthHttp class in angular2-jwt not present in 'npm i @auth0/angular-jwt'

I have installed the @auth0/angular-jwt package and as in Anular2-jwt there is class called AuthHttp(which will add Bearer automatically and also set into the Authorization header as well).

How can we achieve the same thing with @auth0/angular-jwt

AuthHttp is no more in this module but you can achieve similar behavior with @auth0/angular-jwt . Try adding this configuration to you app module :

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 { }

For more details refer here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM