Commit 057c21b9 authored by wim-vantomme's avatar wim-vantomme

Fixed passing of feathers app object through services setup.

parent b45bbc2a
......@@ -36,7 +36,7 @@ form.addEventListener('submit', (e) => {
jwt: jwt.data
})
})
window.location = "signed-in.html"
window.location = 'signed-in.html'
}).catch((err) => {
console.log(err)
})
......
// Application hooks that run for every service
const logger = require('./hooks/logger');
const logger = require('./hooks/logger')
module.exports = {
before: {
......@@ -31,4 +31,4 @@ module.exports = {
patch: [],
remove: []
}
};
}
......@@ -9,8 +9,8 @@ const feathers = require('@feathersjs/feathers')
const configuration = require('@feathersjs/configuration')
const express = require('@feathersjs/express')
const socketio = require('@feathersjs/socketio')
const authentication = require('@feathersjs/authentication');
const jwt = require('@feathersjs/authentication-jwt');
const authentication = require('@feathersjs/authentication')
const jwt = require('@feathersjs/authentication-jwt')
const middleware = require('./middleware')
const services = require('./services')
......@@ -34,8 +34,8 @@ app.use('/', express.static(app.get('public')))
// Set up Plugins and providers
app.configure(express.rest())
app.configure(socketio())
app.configure(authentication({secret: "dit is een secret", service: 'private'}));
app.configure(jwt());
app.configure(authentication({secret: 'dit is een secret', service: 'private'}))
app.configure(jwt())
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware)
......
......@@ -57,4 +57,4 @@ module.exports = function (app) {
// app.channel(`emails/${data.recipientEmail}`)
// ];
// });
};
}
......@@ -3,9 +3,16 @@ const sodium = require('libsodium-wrappers')
const jwt = require('jsonwebtoken')
const fileUtils = require('../../utils/fileUtils')
// const app = require('../../app')
class Service {
constructor (options) {
this.options = options || {};
this.options = options || {}
}
// This method is required to be able to pass the feathers app object.
setup (app) {
this.app = app
}
async find (params) {
......@@ -13,9 +20,9 @@ class Service {
}
async get (id, params) {
if(id === 'nonce') {
const nonce = sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES)
return sodium.to_hex(nonce)
if (id === 'nonce') {
const nonce = sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES)
return sodium.to_hex(nonce)
}
}
......@@ -24,31 +31,33 @@ class Service {
const keys = await fileUtils.readFile('./server/files/keys.json')
const publicKey = JSON.parse(keys).publicKey
const nonce = sodium.crypto_sign_open(signedMessage, sodium.from_hex(publicKey))
if(nonce == -1) {
const error = new errors.NotAuthenticated('You\'re not authorized', err)
if (nonce == -1) {
const error = new errors.NotAuthenticated('You\'re not authorized')
throw error
} else {
const salt = sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES)
this.options.app.set('secret', salt)
return jwt.sign({ nonce }, sodium.to_hex(salt));
console.log(this.app)
//app.locals({salt})
//app.set('secret', salt)
return jwt.sign({ nonce }, sodium.to_hex(salt))
}
}
async update (id, data, params) {
return data;
return data
}
async patch (id, data, params) {
return data;
return data
}
async remove (id, params) {
return { id };
return { id }
}
}
module.exports = function (options) {
return new Service(options);
};
return new Service(options)
}
module.exports.Service = Service;
module.exports.Service = Service
// Initializes the `authorize` service on path `/authorize`
const createService = require('./authorize.class.js');
const hooks = require('./authorize.hooks');
const createService = require('./authorize.class.js')
const hooks = require('./authorize.hooks')
module.exports = function (app) {
const paginate = app.get('paginate');
const paginate = app.get('paginate')
const options = {
name: 'authorize',
paginate,
app
};
paginate
}
// Initialize our service with any options it requires
app.use('/authorize', createService(options));
app.use('/authorize', createService(options))
// Get our initialized service so that we can register hooks and filters
const service = app.service('authorize');
const service = app.service('authorize')
service.hooks(hooks);
service.hooks(hooks)
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment