@rapidnetworks/sam
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

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 🔌

npm i @rapidnetworks/sam

This module includes its own type definitions

Usage 🚀

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>>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @rapidnetworks/sam

Weekly Downloads

0

Version

2.0.2

License

GPL-3.0-only

Unpacked Size

144 kB

Total Files

15

Last publish

Collaborators

  • lil_we3zy