New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hapi-auth-jwt2

Package Overview
Dependencies
Maintainers
1
Versions
94
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-auth-jwt2 - npm Package Compare versions

Comparing version 8.4.0 to 8.5.0

17

lib/index.js

@@ -196,7 +196,8 @@ 'use strict';

try {
let { isValid, credentials, response } = await options.validate(
verify_decoded,
request,
h
);
let {
isValid,
credentials,
response,
errorMessage,
} = await options.validate(verify_decoded, request, h);
if (response !== undefined) {

@@ -208,3 +209,7 @@ return h.response(response).takeover();

return h.unauthenticated(
raiseError('unauthorized', 'Invalid credentials', tokenType),
raiseError(
'unauthorized',
errorMessage || 'Invalid credentials',
tokenType
),
{ credentials: decoded }

@@ -211,0 +216,0 @@ );

{
"name": "hapi-auth-jwt2",
"version": "8.4.0",
"version": "8.5.0",
"description": "Hapi.js Authentication Plugin/Scheme using JSON Web Tokens (JWT)",

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

@@ -184,2 +184,3 @@ # Hapi Auth using JSON Web Tokens (JWT)

- `response` - (***optional***) If provided will be used immediately as a takeover response.
- `errorMessage` - (***optional*** *defaults to* `'Invalid credentials'`) - the error message raised to Boom if the token is invalid (passed to `errorFunc` as `errorContext.message`)

@@ -186,0 +187,0 @@ ### *Optional* Parameters

@@ -20,2 +20,8 @@ const test = require('tape');

}
if (decoded.id === 139) {
return { isValid: false }
}
if (decoded.id === 140) {
return { isValid: false, errorMessage: 'Bad ID' }
}
return { response: h.redirect('https://dwyl.com') }

@@ -46,4 +52,13 @@ },

t.equal(response.headers.location, 'https://dwyl.com', 'Server redirect header');
options.headers.Authorization = JWT.sign({id: 139, name: 'Test'}, secret);
response = await server.inject(options);
t.equal(response.statusCode, 401, 'Server errors when isValid false');
t.equal(response.result.message, 'Invalid credentials', 'Default error message when custom not provided');
options.headers.Authorization = JWT.sign({id: 140, name: 'Test'}, secret);
response = await server.inject(options);
t.equal(response.result.message, 'Bad ID', 'Custom error message when provided');
t.end();
});
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