@kofile/jwt-client

4.0.1 • Public • Published

@kofile/jwt-client

JavaScript Style Guide Build Status Coverage Status @kofile/jwt-client Commitizen friendly

A simple JWT Reader.

Usage

const makeClient = require('@kofile/jwt-client')
const client = makeClient(jwt)

API

client.userId

client.tenantId

client.ort

client.encoded

client.dump()

client.getRoleIdForTenant(tenantId)

client.validate()

Usage Example

const makeClient = require('@kofile/jwt-client')
const payload = {
  id: 123,
  tenantId: '48121',
  ort: 'dsgsgasdgdfhws',
  tenant: {
    48121: {
      authorization: 1
    }
  }
}
const jwt = jsonwebtoken.sign(payload, 'key')

const client = makeClient(jwt)

// get user id
client.userId //=> 123

// get tenant id
client.tenantId //=> 48121

//get ort
client.ort //=> dsgsgasdgdfhws

// get encoded jwt
client.encoded //=> jsonwebtoken.sign(payload, 'key')

// get the entire payload body
client.dump() //=> payload

// get role id for a tenant
client.getRoleIdForTenant(tenantId) //=> 1

// check if an error is a custom JwtError
makeClient.isAJwtError(myError)

// validate that `userId` and `ort` are not null or undefined
//
// - throws a custom JwtError if a key is null or undefined
// - returns true if validations pass
// - pass in the keys of the public API, **not** internal structure
client.validate(['userId', 'ort'])

Readme

Keywords

none

Package Sidebar

Install

npm i @kofile/jwt-client

Weekly Downloads

6

Version

4.0.1

License

MIT

Unpacked Size

5.16 kB

Total Files

4

Last publish

Collaborators

  • hd-kofile
  • oliverhoff
  • fernandofgovos
  • bwgovos
  • juandagovos
  • matt_huntsberry
  • afine_govos
  • bthomas_govos
  • chrisburch-govos
  • rarzate
  • narekdaghlaryan
  • daniltarasov
  • kofilesystems
  • neezer
  • scottkof
  • jbalfantz
  • ngraves
  • arturhovhannisyan1994volo
  • rachel-ftw
  • warrenyoungkofile