🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

a4-http-authorization-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a4-http-authorization-interceptor

OAuth Token injector for angular project

9.0.0
latest
npm
Version published
Weekly downloads
13
85.71%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

angular

FAQs

Package last updated on 08 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts