a4-http-authorization-interceptor
Angular 7 Http Authorization Interceptor
How-To
Install
npm install a4-http-authorization-interceptor
app.module.ts
- Add
HttpAuthorizationModule
to imports of the app.module.ts
.
...
import { HttpAuthorizationModule } from 'a4-http-authorization';
...
@NgModule({
declarations: [
AppComponent
],
imports: [
...,
HttpAuthorizationModule,
...
],
...
})
Inject the service
constructor(private httpAuthorizationService: HttpAuthorizationService) { }
Set the token's cookie name
this.httpAuthorizationService.setTokenCookieName('oauth-cookie');
this.httpAuthorizationService.setHttpAuthorizationCallback(req => {
return true;
});
const header = this.httpAuthorizationService.getAuthorizationHeader();
This will return Bearer <token>
if cookie is found, otherwise it returns an empty string ('').