Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@http-ext/plugin-auth

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@http-ext/plugin-auth

> A auth plugin for [HttpExt](https://github.com/jscutlery/http-ext).

  • 2.0.2
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

@http-ext/plugin-auth

A auth plugin for HttpExt.

This plugin takes care of handling authorization by:

  • adding the Authorization header with the given token automatically for each request matching a custom condition,
  • triggering a custom token expiration logic on 401 Unauthorized http responses.

This plugins helps avoiding all the http interceptor boilerplate required to add the authorization token and detect token expiration.

Using matchers like matchOrigin, we'll ensure that the token is sent to the right API. This also helps using different tokens for different APIs in the same app.

Requirements

The plugin requires @http-ext/core and @http-ext/angular to be installed.

Installation

yarn add @http-ext/plugin-cache @http-ext/core

or

npm install @http-ext/plugin-cache @http-ext/core

Usage

import { HttpExtModule } from '@http-ext/angular';
import { createAuthPlugin } from '@http-ext/plugin-auth';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    HttpClientModule,
    HttpExtModule.forRoot({
      deps: [AuthService],
      config: (authService: AuthService) =>
        createAuthPlugin({
          shouldHandleRequest: matchOrigin('https://secure-origin.com'),
          token: authService.getToken(), // Returns an Observable<string>.
          onUnauthorized: () => authService.markTokenExpired()
        })
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

Available options

You can give a partial configuration object it will be merged with default values.

PropertyTypeRequiredDefault valueDescription
tokenObservable<string>YesundefinedThe bearer token that will be added to every matching request in the Authorization header.
onUnauthorizedOnUnauthorizedNoundefinedA function executed when an unauthorized response is thrown.
shouldHandleRequestRequestConditionNomatchOrigin('https://my-origin.com')Predicate function to know which request the plugin should handle.

To know more about the shouldHandleRequest property check-out the conditional handling section.

FAQs

Package last updated on 08 Apr 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc