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

@colearn/microservices-kit

Package Overview
Dependencies
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colearn/microservices-kit - npm Package Compare versions

Comparing version 0.0.37 to 0.0.38

4

lib/jwt.d.ts
/// <reference types="node" />
import type { NextFunction, Response, Request } from 'express';
export declare function jwtMiddleware(secret: string | undefined, required?: boolean): (req: Request, res: Response, next: NextFunction) => Promise<void | NodeJS.Immediate>;
import { Params } from 'express-jwt';
export declare function extractToken(req: Request): string | undefined;
export declare function jwtMiddleware({ secret, algorithms, credentialsRequired, requestProperty, ...rest }: Params): (req: Request, res: Response, next: NextFunction) => Promise<void | NodeJS.Immediate>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jwtMiddleware = void 0;
exports.jwtMiddleware = exports.extractToken = void 0;
const express_jwt_1 = require("express-jwt");
const errors_1 = require("./errors");
function jwtMiddleware(secret, required = false) {
function extractBearerToken(req) {
if (!req.headers.authorization) {
return undefined;
}
const parts = req.headers.authorization.split(' ');
if (parts.length === 2) {
const [scheme, credentials] = parts;
if (/^Bearer$/i.test(scheme)) {
return credentials;
}
}
throw new errors_1.UnauthorizedError('Format is "Authorization: Bearer [token]"');
}
function extractTokenFromCookie(req, cookieName) {
if (!cookieName) {
return undefined;
}
return req.cookies[cookieName];
}
function extractToken(req) {
return extractBearerToken(req) || extractTokenFromCookie(req);
}
exports.extractToken = extractToken;
function jwtMiddleware({ secret, algorithms = ['HS256'], credentialsRequired = false, requestProperty = 'user', ...rest }) {
if (!secret) {

@@ -12,5 +35,6 @@ throw new TypeError('jwt secret is not specified');

secret,
algorithms: ['HS256'],
credentialsRequired: required,
requestProperty: 'user',
algorithms,
credentialsRequired,
requestProperty,
...rest,
});

@@ -17,0 +41,0 @@ return (req, res, next) => middleware(req, res, (err) => {

{
"name": "@colearn/microservices-kit",
"version": "0.0.37",
"version": "0.0.38",
"description": "colearn microservice kit",

@@ -5,0 +5,0 @@ "author": "Colearn",

Sorry, the diff of this file is not supported yet

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