New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jwt-service

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwt-service

A simple wrapper for a simpler JWT surface API

latest
Source
npmnpm
Version
12.0.0
Version published
Weekly downloads
178
-42.58%
Maintainers
1
Weekly downloads
 
Created
Source

jwt-service

A simple wrapper for a simpler JWT surface API

GitHub license

This wrapper is directly usable with Knifecycle.

Overriding

Let's say you wanna create a sub-service of this one with custom inputs, for say, refresh tokens in a Whook project, here is how you would do:

import initJWT, { JWTServiceConfig } from 'jwt_service';
import { inject } from 'knifecycle';

export type RefreshJWTServiceConfig = {
  ENV: JWTServiceConfig['ENV'];
  REFRESH_JWT_SECRET_ENV_NAME: JWTServiceConfig['JWT_SECRET_ENV_NAME'];
  REFRESH_JWT: JWTServiceConfig['JWT'];
};

export default inject(
  [
    '?JWT_SECRET_ENV_NAME>REFRESH_JWT_SECRET_ENV_NAME',
    'JWT>REFRESH_JWT',
    '?ENV',
    '?log',
    '?time',
  ],
  initJWT,
);

API

Functions

initJWT(services)Promise.<JWTService>

Instantiate the JWT service

Typedefs

JWTService

initJWT(services) ⇒ Promise.<JWTService>

Instantiate the JWT service

Kind: global function
Returns: Promise.<JWTService> - A promise of the jwt service

ParamTypeDescription
servicesObjectThe services to inject
[services.JWT_SECRET_ENV_NAME]functionThe environment variable name in which to pick-up the JWT secret
[services.ENV]ObjectAn environment object
services.JWTfunctionThe JWT service configuration object
[services.log]functionA logging function
[services.time]functionA function returning the current timestamp

Example

import initJWTService from 'jwt-service';

const jwt = await initJWTService({
  JWT: {
    secret: 'secret',
    duration: '2d',
    tolerance: '2h',
    algorithms: ['HS256'],
  },
  log: console.log.bind(console),
  time: Date.now.bind(Date),
});

const token = await jwt.sign({ my: 'payload' });

JWTService

Kind: global typedef

JWTService.sign(payload, [algorithm]) ⇒ Promise.<JWTSignResult>

Sign the given payload

Kind: static method of JWTService
Returns: Promise.<JWTSignResult> - A promise to be resolved with the signed token.

ParamTypeDescription
payloadObjectThe payload to sign
[algorithm]StringThe signing algorithm

Example

const token = await jwt.sign({ my: 'payload' });

JWTService.verify([token]) ⇒ Promise.<Object>

Verify and decode the given token

Kind: static method of JWTService
Returns: Promise.<Object> - A promise to be resolved with the token payload.

ParamTypeDescription
[token]StringThe token to decode

Example

const payload = await jwt.verify('my.jwt.token');

Authors

License

MIT

Keywords

jwt

FAQs

Package last updated on 27 Mar 2026

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