a4-http-authorization-interceptor
TypeScript icon, indicating that this package has built-in type declarations

9.0.0 • Public • Published

a4-http-authorization-interceptor

Angular 7 Http Authorization Interceptor

How-To

Install

npm install a4-http-authorization-interceptor

app.module.ts

  1. 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 httpAuthorizationServiceHttpAuthorizationService) { }

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 ('').

Readme

Keywords

Package Sidebar

Install

npm i a4-http-authorization-interceptor

Weekly Downloads

11

Version

9.0.0

License

MIT

Unpacked Size

111 kB

Total Files

26

Last publish

Collaborators

  • cccheng