Comparing version 7.1.1 to 8.0.0
{ | ||
"name": "get-jwks", | ||
"version": "7.1.1", | ||
"version": "8.0.0", | ||
"description": "Fetch utils for JWKS keys", | ||
@@ -38,4 +38,4 @@ "main": "src/get-jwks.js", | ||
"@fastify/jwt": "^6.1.0", | ||
"@types/lru-cache": "^7.4.0", | ||
"@types/node": "^18.6.5", | ||
"@types/node-fetch": "^2.6.2", | ||
"eslint": "^8.6.0", | ||
@@ -42,0 +42,0 @@ "fast-jwt": "^1.1.2", |
@@ -7,8 +7,3 @@ 'use strict' | ||
const errors = { | ||
NO_JWKS_URI: 'No valid jwks_uri key found in providerConfig', | ||
NO_JWKS: 'No JWKS found in the response.', | ||
JWK_NOT_FOUND: 'No matching JWK found in the set.', | ||
DOMAIN_NOT_ALLOWED: 'The domain is not allowed.', | ||
} | ||
const { errorCode, GetJwksError } = require('./error') | ||
@@ -50,10 +45,10 @@ function ensureTrailingSlash(domain) { | ||
if (!response.ok) { | ||
const error = new Error(response.statusText) | ||
error.response = response | ||
error.body = body | ||
throw error | ||
throw new GetJwksError(errorCode.OPENID_CONFIGURATION_REQUEST_FAILED, { | ||
response, | ||
body, | ||
}) | ||
} | ||
if (!body.jwks_uri) { | ||
throw new Error(errors.NO_JWKS_URI) | ||
throw new GetJwksError(errorCode.NO_JWKS_URI) | ||
} | ||
@@ -74,3 +69,4 @@ | ||
if (allowedDomains.length && !allowedDomains.includes(normalizedDomain)) { | ||
return Promise.reject(new Error(errors.DOMAIN_NOT_ALLOWED)) | ||
const error = new GetJwksError(errorCode.DOMAIN_NOT_ALLOWED) | ||
return Promise.reject(error) | ||
} | ||
@@ -115,10 +111,10 @@ | ||
if (!response.ok) { | ||
const error = new Error(response.statusText) | ||
error.response = response | ||
error.body = body | ||
throw error | ||
throw new GetJwksError(errorCode.JWKS_REQUEST_FAILED, { | ||
response, | ||
body, | ||
}) | ||
} | ||
if (!body.keys || body.keys.length === 0) { | ||
throw new Error(errors.NO_JWKS) | ||
throw new GetJwksError(errorCode.NO_JWKS) | ||
} | ||
@@ -133,3 +129,3 @@ | ||
if (!jwk) { | ||
throw new Error(errors.JWK_NOT_FOUND) | ||
throw new GetJwksError(errorCode.JWK_NOT_FOUND) | ||
} | ||
@@ -136,0 +132,0 @@ |
@@ -8,2 +8,3 @@ 'use strict' | ||
const buildGetJwks = require('../src/get-jwks') | ||
const { GetJwksError, errorCode } = require('../src/error') | ||
@@ -25,4 +26,7 @@ t.beforeEach(async () => { | ||
const expectedError = new Error('Internal Server Error') | ||
expectedError.body = { msg: 'boom' } | ||
const expectedError = { | ||
name: GetJwksError.name, | ||
code: errorCode.JWKS_REQUEST_FAILED, | ||
body: { msg: 'boom' }, | ||
} | ||
@@ -29,0 +33,0 @@ await t.rejects(getJwks.getJwk({ domain, alg, kid }), expectedError) |
@@ -8,2 +8,3 @@ 'use strict' | ||
const buildGetJwks = require('../src/get-jwks') | ||
const { errorCode, GetJwksError } = require('../src/error') | ||
@@ -27,5 +28,7 @@ t.beforeEach(async () => { | ||
const expectedError = new Error('Internal Server Error') | ||
expectedError.body = { msg: 'baam' } | ||
const expectedError = { | ||
name: GetJwksError.name, | ||
code: errorCode.OPENID_CONFIGURATION_REQUEST_FAILED, | ||
body: { msg: 'baam' }, | ||
} | ||
await t.rejects(getJwks.getJwk({ domain, alg, kid }), expectedError) | ||
@@ -41,3 +44,7 @@ }) | ||
const expectedError = new Error('Internal Server Error') | ||
const expectedError = { | ||
name: GetJwksError.name, | ||
code: errorCode.JWKS_REQUEST_FAILED, | ||
body: { msg: 'boom' }, | ||
} | ||
expectedError.body = { msg: 'boom' } | ||
@@ -44,0 +51,0 @@ |
@@ -9,2 +9,3 @@ 'use strict' | ||
const buildGetJwks = require('../src/get-jwks') | ||
const { GetJwksError, errorCode } = require('../src/error') | ||
@@ -26,3 +27,7 @@ t.beforeEach(async () => { | ||
const expectedError = new Error('Internal Server Error') | ||
const expectedError = { | ||
name: GetJwksError.name, | ||
code: errorCode.OPENID_CONFIGURATION_REQUEST_FAILED, | ||
body: { msg: 'baam' }, | ||
} | ||
@@ -40,5 +45,6 @@ await t.rejects(getJwks.getJwksUri(domain), expectedError) | ||
const expectedError = new Error( | ||
'No valid jwks_uri key found in providerConfig' | ||
) | ||
const expectedError = { | ||
name: GetJwksError.name, | ||
code: errorCode.NO_JWKS_URI, | ||
} | ||
@@ -45,0 +51,0 @@ await t.rejects(getJwks.getJwksUri(domain), expectedError) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50640
30
968