Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kofile/jwt-client

Package Overview
Dependencies
Maintainers
26
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kofile/jwt-client

A simple JWT reader

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
26
Created
Source

@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'])

FAQs

Package last updated on 26 Jun 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc