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

fastify-jwt

Package Overview
Dependencies
Maintainers
7
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-jwt - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

25

jwt.d.ts
import * as fastify from 'fastify';
import * as jwt from 'jsonwebtoken';
declare module 'fastify' {
namespace JWTTypes {
type SignPayloadType = object | string | Buffer;
type VerifyPayloadType = object | string;
type DecodePayloadType = object | string;
interface SignCallback extends jwt.SignCallback { }
declare namespace JWTTypes {
type SignPayloadType = object | string | Buffer;
type VerifyPayloadType = object | string;
type DecodePayloadType = object | string;
interface VerifyCallback<Decoded extends VerifyPayloadType> extends jwt.VerifyCallback {
(err: jwt.VerifyErrors, decoded: Decoded): void;
}
interface SignCallback extends jwt.SignCallback { }
interface VerifyCallback<Decoded extends VerifyPayloadType> extends jwt.VerifyCallback {
(err: jwt.VerifyErrors, decoded: Decoded): void;
}
}
declare module 'fastify' {
interface JWT {

@@ -61,5 +62,7 @@ options: {

type Secret = jwt.Secret | ((request: fastify.FastifyRequest, reply: fastify.FastifyReply, cb: (e: Error | null, secret: string | undefined) => void) => void);
declare namespace fastifyJWT {
export interface FastifyJWTOptions {
secret: jwt.Secret | { public: jwt.Secret; private: jwt.Secret };
secret: Secret | { public: Secret; private: Secret };
decode?: jwt.DecodeOptions;

@@ -78,3 +81,3 @@ sign?: jwt.SignOptions;

}
trusted?: (request: fastify.FastifyRequest, decodedToken: { [k: string]: any }) => boolean | Promise<boolean> | fastify.JWTTypes.SignPayloadType | Promise<fastify.JWTTypes.SignPayloadType>
trusted?: (request: fastify.FastifyRequest, decodedToken: { [k: string]: any }) => boolean | Promise<boolean> | JWTTypes.SignPayloadType | Promise<JWTTypes.SignPayloadType>
}

@@ -81,0 +84,0 @@

import fastify from 'fastify';
import fastifyJwt from './jwt'
import fastifyJwt, { FastifyJWTOptions } from './jwt'
import { expectAssignable } from 'tsd'

@@ -7,4 +7,19 @@

app.register(fastifyJwt, {
secret: process.env.usePublicPrivateKeys ? "supersecret" : { public: 'publicKey', private: 'privateKey' },
const jwtOptions: FastifyJWTOptions = {
secret: {
secret: 'supersecret',
publicPrivateKey: {
public: 'publicKey',
private: 'privateKey'
},
secretFn: (_req, _rep, cb) => { cb(null, 'supersecret') },
publicPrivateKeyFn: {
public: (_req, _rep, cb) => { cb(null, 'publicKey') },
private: 'privateKey'
},
publicPrivateKeyFn2: {
public: 'publicKey',
private: (_req, _rep, cb) => { cb(null, 'privateKey') },
}
}[process.env.secretOption!],
sign: {

@@ -30,5 +45,9 @@ expiresIn: '1h'

},
trusted: () => true,
});
trusted: () => false || '' || Buffer.from('foo')
}
app.register(fastifyJwt, jwtOptions);
app.register(fastifyJwt, {...jwtOptions, trusted: () => Promise.resolve(false || '' || Buffer.from('foo')) })
// expect jwt and its subsequent methods have merged with the fastify instance

@@ -35,0 +54,0 @@ expectAssignable<object>(app.jwt)

{
"name": "fastify-jwt",
"version": "2.1.2",
"version": "2.1.3",
"description": "JWT utils for Fastify",

@@ -40,9 +40,9 @@ "main": "jwt.js",

"devDependencies": {
"fastify": "^3.0.0-rc.4",
"fastify": "^3.0.0",
"fastify-cookie": "^4.0.1",
"standard": "^14.0.2",
"tap": "^14.10.7",
"tsd": "^0.11.0",
"tsd": "^0.13.1",
"typescript": "^3.2.2"
}
}
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