Comparing version 1.0.0 to 1.0.1
@@ -31,2 +31,3 @@ /** | ||
function ByuJWT(options) { | ||
const byuJwt = {}; | ||
@@ -45,61 +46,64 @@ // normalize options | ||
if (!(this instanceof ByuJWT)) return new ByuJWT(options) | ||
this.options = Object.assign({}, options) | ||
// store options | ||
byuJwt.options = Object.assign({}, options) | ||
// set cache TTL | ||
this.cache = Cache() | ||
this.cache.setTTL(options.cacheTTL) | ||
byuJwt.cache = Cache() | ||
byuJwt.cache.setTTL(options.cacheTTL) | ||
} | ||
byuJwt.authenticate = headers => { | ||
return init(byuJwt.cache) | ||
.then(openIdConfig => authenticate(byuJwt.options, openIdConfig, headers)) | ||
} | ||
ByuJWT.prototype.authenticate = function(headers) { | ||
return init(this.cache) | ||
.then(openIdConfig => authenticate(this.options, openIdConfig, headers)) | ||
} | ||
byuJwt.authenticateUAPIMiddleware = function(req, res, next) { | ||
this.authenticate(req.headers) | ||
.then(verifiedJWTs => { | ||
req.verifiedJWTs = verifiedJWTs | ||
next() | ||
}) | ||
.catch(err => { | ||
console.error(err.stack) | ||
const response = err instanceof AuthenticationError | ||
? { code: 401, message: err.message } | ||
: { code: 500, message: 'Error determining authentication' } | ||
res.status(response.code).send({ metadata: { validation_response: response } }) | ||
}) | ||
} | ||
ByuJWT.prototype.authenticateUAPIMiddleware = function(req, res, next) { | ||
this.authenticate(req.headers) | ||
.then(verifiedJWTs => { | ||
req.verifiedJWTs = verifiedJWTs | ||
next() | ||
}) | ||
.catch(err => { | ||
console.error(err.stack) | ||
const response = err instanceof AuthenticationError | ||
? { code: 401, message: err.message } | ||
: { code: 500, message: 'Error determining authentication' } | ||
res.status(response.code).send({ metadata: { validation_response: response } }) | ||
}) | ||
} | ||
byuJwt.decodeJWT = function(jwt) { | ||
return init(this.cache) | ||
.then(openIdConfig => decodeJWT(this.options, openIdConfig, jwt)) | ||
} | ||
ByuJWT.prototype.decodeJWT = function(jwt) { | ||
return init(this.cache) | ||
.then(openIdConfig => decodeJWT(this.options, openIdConfig, jwt)) | ||
} | ||
byuJwt.getOpenIdConfiguration = function() { | ||
return getOpenIdConfiguration(this.cache) | ||
} | ||
ByuJWT.prototype.getOpenIdConfiguration = function() { | ||
return getOpenIdConfiguration(this.cache) | ||
} | ||
byuJwt.getPublicKey = function() { | ||
return init(this.cache) | ||
.then(getPublicKey) | ||
} | ||
ByuJWT.prototype.getPublicKey = function() { | ||
return init(this.cache) | ||
.then(getPublicKey) | ||
} | ||
byuJwt.verifyJWT = function(jwt) { | ||
return init(this.cache) | ||
.then(openIdConfig => verifyJWT(this.options, openIdConfig, jwt)) | ||
.then(() => true) | ||
.catch(() => false) | ||
} | ||
ByuJWT.prototype.verifyJWT = function(jwt) { | ||
return init(this.cache) | ||
.then(openIdConfig => verifyJWT(this.options, openIdConfig, jwt)) | ||
.then(() => true) | ||
.catch(() => false) | ||
Object.defineProperties(byuJwt, { | ||
cacheTTL: { | ||
get: function() { return this.cache.getTTL() }, | ||
set: function(ttl) { this.cache.setTTL(ttl) } | ||
} | ||
}); | ||
return byuJwt; | ||
} | ||
Object.defineProperties(ByuJWT.prototype, { | ||
cacheTTL: { | ||
get: function() { return this.cache.getTTL() }, | ||
set: function(ttl) { this.cache.setTTL(ttl) } | ||
} | ||
}); | ||
Object.defineProperties(ByuJWT, { | ||
@@ -106,0 +110,0 @@ 'BYU_JWT_HEADER_CURRENT': { |
{ | ||
"name": "byu-jwt", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "The byu-jwt module provides helpful functions to retrieve a specified BYU .well-known URL and verify BYU signed JWTs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40885
595
2