a4-http-authorization-interceptor
v9.0.0
Published
OAuth Token injector for angular project
Downloads
33
Readme
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 theapp.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');
Set Authroization Header Call Back
this.httpAuthorizationService.setHttpAuthorizationCallback(req => {
// your logic here
return true; // return true to allow injector to inject the authorization header
// return false and injector will not inject the authorization header
});
Get Authorization Header
const header = this.httpAuthorizationService.getAuthorizationHeader();
This will return Bearer <token>
if cookie is found, otherwise it returns an empty string ('').