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

flora-auth-jwt

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flora-auth-jwt - npm Package Compare versions

Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4

75

index.js

@@ -18,50 +18,40 @@ 'use strict';

api.on('request', async ev => {
const request = ev.request;
// decode and verify JSON Web Token
api.on('request', async ({ request }) => {
/**
* Decode and verify JSON Web Token
* @private
*/
async function decode(token) {
if (!token) {
if (typeof options.validate !== 'function') {
request._auth = null;
return null;
}
let decoded = null;
if (token) {
api.log.trace('Verifying JWT: ' + token);
const validated = await options.validate(null, request);
request._auth = validated || null;
return null;
}
try {
decoded = jwt.verify(token, options.secret);
} catch (err) {
api.log.trace(err);
return new Promise((resolve, reject) => {
api.log.trace('Verifying JWT: ' + token);
jwt.verify(token, options.secret, (err, decoded) => {
if (err && err.message === 'jwt expired') {
api.log.trace(err);
if (err.message === 'jwt expired') {
const e = new AuthenticationError('Expired token received for JSON Web Token validation');
e.code = 'ERR_TOKEN_EXPIRED';
return reject(e);
throw e;
}
if (err) {
api.log.trace(err);
const e = new AuthenticationError('Invalid signature received for JSON Web Token validation');
e.code = 'ERR_INVALID_TOKEN_SIGNATURE';
return reject(e);
}
const e = new AuthenticationError('Invalid signature received for JSON Web Token validation');
e.code = 'ERR_INVALID_TOKEN_SIGNATURE';
throw e;
}
api.log.trace('Verified authentication token: ', decoded);
api.log.trace('Verified authentication token: ', decoded);
}
if (typeof options.validate !== 'function') {
request._auth = decoded;
return resolve();
}
const validated = typeof options.validate === 'function' ? await options.validate(decoded, request) : decoded;
return resolve(
options.validate(decoded, request).then(validated => {
if (!request._auth) request._auth = validated || decoded;
})
);
});
});
if (!request._auth) request._auth = validated;
if (options.credentialsRequired && !request._auth) {
const e = new AuthenticationError('No authorization token was found');
e.code = 'ERR_MISSING_TOKEN';
throw e;
}
}

@@ -93,11 +83,2 @@

});
if (options.credentialsRequired) return;
api.on('request', ev => {
if (ev.request._auth || !options.credentialsRequired) return;
const e = new AuthenticationError('No authorization token was found');
e.code = 'ERR_MISSING_TOKEN';
throw e;
});
};
{
"name": "flora-auth-jwt",
"version": "2.0.0-alpha.3",
"version": "2.0.0-alpha.4",
"description": "JSON Web Token authentication for Flora",

@@ -5,0 +5,0 @@ "main": "index.js",

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