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

multicolour-hapi-jwt

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multicolour-hapi-jwt - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

66

index.js

@@ -25,25 +25,38 @@ "use strict"

class Multicolour_Auth_JWT {
validate(multicolour, decoded, callback) {
multicolour.get("database").get("models").multicolour_user
constructor(host) {
host.request("host")._enable_user_model()
}
/**
* Validate values against the database and
* call the callback with the results.
*
* @param {Object} decoded values to validate against database.
* @param {Function} callback to execute with validation results.
*/
validate(decoded, callback) {
this.multicolour.get("database").get("models").multicolour_user
.findOne({ id: decoded.id, email: decoded.email, username: decoded.username })
.populateAll()
.exec((err, user) => {
if (err) {
callback(err, false)
}
else if (!user) {
if (err)
callback(err, false, {})
else if (!user)
callback(null, false)
}
else {
else
callback(null, true, user)
}
})
}
/**
* Attempt to authorise a posted payload's claim.
*
* @param {String} identifier; the username/email/whatever identifier.
* @param {String} password to authorise.
* @param {String} identifier_field; the key in the payload to validate.
*/
auth(identifier, password, callback, identifier_field) {
identifier_field = identifier_field || "email"
const multicolour = this.request("host")
//const method = request.headers.accept
const multicolour = this.multicolour
const mc_utils = require("multicolour/lib/utils")

@@ -55,4 +68,4 @@ const models = multicolour.get("database").get("models")

models
.multicolour_user.findOne({
models.multicolour_user
.findOne({
[identifier_field]: identifier,

@@ -63,7 +76,6 @@ requires_password: false

if (!user) {
return callback(new Error("Invalid login", 403))
return callback(boom.unauthorized())
}
// We're good to create a session.
else {
// Hash the password.

@@ -73,3 +85,3 @@ mc_utils.hash_password(password, user.salt, hashed_password => {

if (user.password !== hashed_password) {
return callback(new Error("Invalid login"))
return callback(boom.unauthorized())
}

@@ -110,10 +122,10 @@

// Get the host and server.
const host = generator.request("host")
this.multicolour = generator.request("host")
const server = generator.request("raw")
// Get the config.
const config = host.get("config").get("auth")
const config = this.multicolour.get("config").get("auth")
// Register the session model with the hosting Multicolour's Waterline instance.
host.get("database").get("definitions").session = require("./session-model")
this.multicolour.get("database").register_new_model(require.resolve("./session-model"))

@@ -146,4 +158,3 @@ generator

key: config.password,
validateFunc: (decoded, request, callback) =>
this.validate(host, decoded, callback),
validateFunc: (decoded, request, callback) => this.validate(decoded, callback),
verifyOptions: {

@@ -158,3 +169,3 @@ algorithms: config.algorithms || [ "HS256" ]

// Headers for the session endpoints.
const headers = host.request("header_validator").get()
const headers = this.multicolour.request("header_validator").get()
delete headers.authorization

@@ -169,3 +180,3 @@

const method = request.headers.accept
const models = host.get("database").get("models")
const models = this.multicolour.get("database").get("models")

@@ -177,7 +188,6 @@ const args = {

// Check for errors.
if (err) {
if (err)
reply(boom.wrap(err))
}
get_decorator_for_apply_value(reply, method)(session, models.session).code(202)
else
get_decorator_for_apply_value(reply, method)(session, models.session).code(202)
}

@@ -184,0 +194,0 @@ }

{
"name": "multicolour-hapi-jwt",
"version": "0.1.3",
"version": "0.1.4",
"description": "JWT Auth plugin for HapiJS Multicolour",

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

@@ -7,2 +7,4 @@ "use strict"

module.exports = {
identity: "session",
// Session's details.

@@ -9,0 +11,0 @@ attributes: {

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