2.0.2 • Published 7 months ago

@rapidnetworks/sam v2.0.2

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
7 months ago

S.A.M - Splynx Authentication Module

https://nodei.co/npm/@rapidnetworks/sam.png?mini=true code style: prettier


About

Wow, I am really getting tired of trying to implement the authentication for Splynx everytime I start a new project.

This module is built for ongoing projects involving our (at time of writing) ISP billing software: Splynx. This service uses the v2 API spec for communicating with the Splynx API.

Install :electric_plug:

npm i @rapidnetworks/sam

This module includes its own type definitions

Usage :rocket:

This package exposes the 4 different API token types, each having a TTL of 30 minutes. This is just a basic overview of usage of the package, however you can view the official documentation to see the implementation and required information here

1. API Token:

import { apiToken } from '@rapidnetworks/sam';

const token = apiToken(url: string, api_key: string, api_secret: string);

2. Customer Token:

import { customerToken } from '@rapidnetworks/sam';

const token = customerToken(url: string, customer_login: string, customer_password: string);

3. Administrator Token:

import { adminToken } from '@rapidnetworks/sam';

const token = adminToken(url: string, admin_login: string, admin_password: string, 2fa_code?: string, 2fa_fingerprint?: string);

4. Session Token:

import { sessionToken } from '@rapidnetworks/sam';

const token = sessionToken(url: string, session_id: string);

All of these tokens are part of a base Authentication token class, allowing full access to the following methods:

1. .refresh(): Promise<void>

This method refreshes the token and updates the token object with the new `access_token` value

2. .delete(): Promise<void>

This method invalidates the `access_token` value, blacklisting it for further use.

The full token object has the following properties:

class AuthorizationToken {
  private url: string;
  public readonly access_token: string;
  public readonly refresh_token: string;
  public readonly access_token_expiration: number;
  public readonly refresh_token_expiration: number;
  public readonly permissions: Record<string, Record<string, string>>;
}
2.0.2

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.1.0

8 months ago