2.0.2 • Published 2 years ago

swa-token v2.0.2

Weekly downloads
-
License
MPL
Repository
-
Last release
2 years ago

Short web application token

The "SWA" token is similar to JWT token but it just shorter.

Install

# npm users
npm i swa-token

# yarn users
yarn add swa-token

How to use

  1. Create SWAT instance
import SWAT from 'swa-token'

const swat = createSWAT('Your-secret-key')
  1. Issue new token
swat.create('1', 'user')
  1. Verify a token
swat.verify(token)
  1. Get token info
swat.parse(token)
  1. Change to difference signature provider
// By default SWAT use HS256 to create signature
// Bellow is example to change HS512 algo
swat.use('HS512')
  1. Custom signature provider
swat.use('YourAlgo', {
  sign: (data: string) => 'signature',
  verify: (data: string, signature: string) => true || false
})