Socket
Socket
Sign inDemoInstall

azure-ad-verify-token

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azure-ad-verify-token - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

11

CHANGELOG.md

@@ -5,2 +5,13 @@ # Changelog

## [2.0.0](https://github.com/justinlettau/azure-ad-verify-token/compare/v1.1.2...v2.0.0) (2021-10-29)
### ⚠ BREAKING CHANGES
* This package is now pure ESM
### Features
* esm package ([6aa4f5b](https://github.com/justinlettau/azure-ad-verify-token/commit/6aa4f5bbd5a0c8b89ab5232a61b83536eedf8105))
### [1.1.2](https://github.com/justinlettau/azure-ad-verify-token/compare/v1.1.1...v1.1.2) (2021-08-27)

@@ -7,0 +18,0 @@

38

dist/cache.js

@@ -1,9 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clear = exports.removeItem = exports.getItem = exports.setDeferredItem = exports.setItem = void 0;
var config_1 = require("./config");
import { getConfig } from './config';
/**
* Public key cache.
*/
var cache = new Map();
const cache = new Map();
/**

@@ -13,4 +10,4 @@ * Get expiry.

function getExpiry() {
var now = new Date().getTime();
var config = config_1.getConfig();
const now = new Date().getTime();
const config = getConfig();
return now + config.cacheLifetime;

@@ -24,3 +21,3 @@ }

*/
function setItem(key, value) {
export function setItem(key, value) {
return cache.set(key, {

@@ -31,3 +28,2 @@ result: Promise.resolve(value),

}
exports.setItem = setItem;
/**

@@ -38,14 +34,13 @@ * Set deferred cache item.

*/
function setDeferredItem(key) {
var done;
var result = new Promise(function (resolve) {
export function setDeferredItem(key) {
let done;
const result = new Promise((resolve) => {
done = resolve;
});
return cache.set(key, {
result: result,
done: done,
result,
done,
expiry: getExpiry(),
});
}
exports.setDeferredItem = setDeferredItem;
/**

@@ -56,5 +51,5 @@ * Get cache item.

*/
function getItem(key) {
var value = cache.get(key);
var now = new Date().getTime();
export function getItem(key) {
const value = cache.get(key);
const now = new Date().getTime();
if (!value) {

@@ -70,3 +65,2 @@ return null;

}
exports.getItem = getItem;
/**

@@ -77,13 +71,11 @@ * Remove cache item.

*/
function removeItem(key) {
export function removeItem(key) {
return cache.delete(key);
}
exports.removeItem = removeItem;
/**
* Clear all items.
*/
function clear() {
export function clear() {
cache.clear();
}
exports.clear = clear;
//# sourceMappingURL=cache.js.map

@@ -1,13 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetConfig = exports.getConfig = exports.setConfig = exports.DEFAULT_CACHE_LIFETIME = void 0;
/**
* Default value for `cacheLifetime`.
*/
exports.DEFAULT_CACHE_LIFETIME = 60 * 60 * 1000; // one hour
export const DEFAULT_CACHE_LIFETIME = 60 * 60 * 1000; // one hour
/**
* Current configuration.
*/
var config = {
cacheLifetime: exports.DEFAULT_CACHE_LIFETIME,
let config = {
cacheLifetime: DEFAULT_CACHE_LIFETIME,
};

@@ -19,22 +16,19 @@ /**

*/
function setConfig(overrides) {
export function setConfig(overrides) {
return Object.assign(config, overrides);
}
exports.setConfig = setConfig;
/**
* Get current configuration.
*/
function getConfig() {
export function getConfig() {
return config;
}
exports.getConfig = getConfig;
/**
* Reset configuration to defaults.
*/
function resetConfig() {
export function resetConfig() {
config = {
cacheLifetime: exports.DEFAULT_CACHE_LIFETIME,
cacheLifetime: DEFAULT_CACHE_LIFETIME,
};
}
exports.resetConfig = resetConfig;
//# sourceMappingURL=config.js.map

@@ -1,9 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verify = exports.setConfig = exports.getConfig = void 0;
var config_1 = require("./config");
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
Object.defineProperty(exports, "setConfig", { enumerable: true, get: function () { return config_1.setConfig; } });
var verify_1 = require("./verify");
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return verify_1.verify; } });
export { getConfig, setConfig } from './config';
export { verify } from './verify';
//# sourceMappingURL=index.js.map

@@ -1,3 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};
//# sourceMappingURL=interfaces.js.map

@@ -1,11 +0,5 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.verify = void 0;
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
var node_fetch_1 = __importDefault(require("node-fetch"));
var rsa_pem_from_mod_exp_1 = __importDefault(require("rsa-pem-from-mod-exp"));
var cache_1 = require("./cache");
import jwt from 'jsonwebtoken';
import fetch from 'node-fetch';
import getPem from 'rsa-pem-from-mod-exp';
import { getItem, setDeferredItem, setItem } from './cache';
/**

@@ -18,3 +12,3 @@ * Get public key.

function getPublicKey(jwksUri, kid) {
var item = cache_1.getItem(kid);
let item = getItem(kid);
if (item) {

@@ -24,9 +18,9 @@ return item.result;

// immediately defer to prevent duplicate calls to get jwks
cache_1.setDeferredItem(kid);
return node_fetch_1.default(jwksUri)
.then(function (res) { return res.json(); })
.then(function (res) {
res.keys.forEach(function (key) {
var existing = cache_1.getItem(key.kid);
var pem = rsa_pem_from_mod_exp_1.default(key.n, key.e);
setDeferredItem(kid);
return fetch(jwksUri)
.then((res) => res.json())
.then((res) => {
res.keys.forEach((key) => {
const existing = getItem(key.kid);
const pem = getPem(key.n, key.e);
if (existing && existing.done) {

@@ -37,6 +31,6 @@ // deferred item

else {
cache_1.setItem(key.kid, pem);
setItem(key.kid, pem);
}
});
item = cache_1.getItem(kid);
item = getItem(kid);
if (!item) {

@@ -54,9 +48,9 @@ throw new Error('public key not found');

*/
function verify(token, options) {
var jwksUri = options.jwksUri, audience = options.audience, issuer = options.issuer;
export function verify(token, options) {
const { jwksUri, audience, issuer } = options;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var decoded;
var kid;
let decoded;
let kid;
try {
decoded = jsonwebtoken_1.default.decode(token, { complete: true, json: true });
decoded = jwt.decode(token, { complete: true, json: true });
kid = decoded.header.kid;

@@ -70,11 +64,8 @@ if (!kid) {

}
return getPublicKey(jwksUri, kid).then(function (key) {
return jsonwebtoken_1.default.verify(token, key, {
algorithms: ['RS256'],
audience: audience,
issuer: issuer,
});
});
return getPublicKey(jwksUri, kid).then((key) => jwt.verify(token, key, {
algorithms: ['RS256'],
audience,
issuer,
}));
}
exports.verify = verify;
//# sourceMappingURL=verify.js.map
{
"name": "azure-ad-verify-token",
"version": "1.1.2",
"version": "2.0.0",
"description": "Verify JWT issued by Azure Active Directory B2C.",

@@ -27,3 +27,7 @@ "keywords": [

},
"main": "dist/index.js",
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"type": "module",
"exports": "./dist/index.js",
"types": "dist/index.d.js",

@@ -48,24 +52,24 @@ "files": [

"@justinlettau/renovate-config": "^0.1.2",
"@types/jest": "^27.0.1",
"@types/jest": "^27.0.2",
"@types/jsonwebtoken": "^8.5.5",
"@types/node-fetch": "^2.5.12",
"@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^4.29.2",
"eslint": "^7.32.0",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^7.0.1",
"jest": "^27.0.6",
"nock": "^13.1.2",
"prettier": "^2.3.2",
"husky": "^7.0.4",
"jest": "^27.3.1",
"nock": "^13.1.4",
"prettier": "^2.4.1",
"pretty-quick": "^3.1.1",
"standard-version": "^9.3.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.3.5"
"standard-version": "^9.3.2",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
},
"dependencies": {
"jsonwebtoken": "^8.5.1",
"node-fetch": "^2.6.1",
"node-fetch": "^2.6.5",
"rsa-pem-from-mod-exp": "^0.8.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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