Socket
Socket
Sign inDemoInstall

@convoyr/plugin-auth

Package Overview
Dependencies
3
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @convoyr/plugin-auth

> A auth plugin for [Convoyr](https://github.com/jscutlery/convoyr).


Version published
Weekly downloads
6
increased by500%
Maintainers
2
Created
Weekly downloads
 

Changelog

Source

4.0.0 (2020-05-30)

Features

  • testing: ✅ run Convoyr core in PluginTester (6f646b1)

BREAKING CHANGES

  • testing: PluginTester args are changed to the following PluginTesterArgs interface. Now the plugin-tester executes the shouldHandleRequest function throught Convoyr core.

Readme

Source

@convoyr/plugin-auth

A auth plugin for Convoyr.

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 @convoyr/core and @convoyr/angular to be installed.

Installation

yarn add @convoyr/plugin-cache @convoyr/core

or

npm install @convoyr/plugin-cache @convoyr/core

Usage

import { ConvoyrModule } from '@convoyr/angular';
import { createAuthPlugin } from '@convoyr/plugin-auth';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    HttpClientModule,
    ConvoyrModule.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.
shouldHandleRequestRequestConditionNoundefinedPredicate function to know which request the plugin should handle.

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

FAQs

Last updated on 30 May 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc