Ind.ie is now Small Technology Foundation.
Commit b45bbc2a authored by Frauke's avatar Frauke

Added feathers authentication

Added authentication to hooks
parent d97f1975
......@@ -5,6 +5,7 @@ const indexedDB = require('./indexedDB')
const Keys = require('./keys')
const form = document.getElementById('register')
const privateForm = document.getElementById('private')
function loadedKeyPair () {
indexedDB.callOnStore('testkeystore', 'keyStore', (store) => {
......@@ -44,3 +45,25 @@ form.addEventListener('submit', (e) => {
console.log(err)
})
})
privateForm.addEventListener('submit', (e) => {
e.preventDefault()
indexedDB.callOnStore('Indienet', 'keyStore', (store) => {
const getData = store.get(2)
getData.onsuccess = (event) => {
const jwt = getData.result.jwt
axios({
url: 'private',
method: 'get',
headers: {'Authorization': `Bearer ${jwt}` },
}).then((data) => {
console.log(data)
}).catch((err) => {
console.log(err)
})
}
})
})
......@@ -13,6 +13,39 @@
"acorn": "5.3.0"
}
},
"@feathersjs/authentication": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@feathersjs/authentication/-/authentication-2.1.1.tgz",
"integrity": "sha512-Lz2/eNr9kwFiKUUqQ0npfwSBUtIAofmoTfMwvam3dgtI23LYMWQbt0+dn0dwQNzSn0WpaRQevLCUTIYE1EZyUQ==",
"requires": {
"@feathersjs/commons": "1.4.0",
"@feathersjs/errors": "3.2.2",
"@feathersjs/socket-commons": "3.1.5",
"debug": "3.1.0",
"jsonwebtoken": "8.1.1",
"lodash.clone": "4.5.0",
"lodash.merge": "4.6.0",
"lodash.omit": "4.5.0",
"lodash.pick": "4.4.0",
"long-timeout": "0.1.1",
"ms": "2.0.0",
"passport": "0.4.0",
"uuid": "3.1.0"
}
},
"@feathersjs/authentication-jwt": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@feathersjs/authentication-jwt/-/authentication-jwt-2.0.0.tgz",
"integrity": "sha512-ZNp0Edkehjt8TIyhp7mxRvQRzQ2t6UPJg+niKh8MdnIKkQ6iGEY8+4NbxP3g8JU0QcUBykS+KxsWmPQzws42FA==",
"requires": {
"@feathersjs/errors": "3.2.2",
"debug": "3.1.0",
"lodash.merge": "4.6.0",
"lodash.omit": "4.5.0",
"lodash.pick": "4.4.0",
"passport-jwt": "3.0.1"
}
},
"@feathersjs/commons": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@feathersjs/commons/-/commons-1.4.0.tgz",
......@@ -3564,6 +3597,11 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz",
"integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4="
},
"isemail": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/isemail/-/isemail-1.2.0.tgz",
"integrity": "sha1-vgPfjMPineTSxd9lASY/H6RZXpo="
},
"isexe": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
......@@ -3581,6 +3619,24 @@
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
},
"joi": {
"version": "6.10.1",
"resolved": "https://registry.npmjs.org/joi/-/joi-6.10.1.tgz",
"integrity": "sha1-TVDDGAeRIgAP5fFq8f+OGRe3fgY=",
"requires": {
"hoek": "2.16.3",
"isemail": "1.2.0",
"moment": "2.20.1",
"topo": "1.1.0"
},
"dependencies": {
"hoek": {
"version": "2.16.3",
"resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz",
"integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0="
}
}
},
"js-tokens": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
......@@ -3902,6 +3958,11 @@
"integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=",
"dev": true
},
"lodash.clone": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz",
"integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y="
},
"lodash.cond": {
"version": "4.5.2",
"resolved": "https://registry.npmjs.org/lodash.cond/-/lodash.cond-4.5.2.tgz",
......@@ -3976,11 +4037,26 @@
"integrity": "sha1-LcvSwofLwKVcxCMovQxzYVDVPj8=",
"dev": true
},
"lodash.merge": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.0.tgz",
"integrity": "sha1-aYhLoUSsM/5plzemCG3v+t0PicU="
},
"lodash.omit": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz",
"integrity": "sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA="
},
"lodash.once": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz",
"integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w="
},
"lodash.pick": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz",
"integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM="
},
"lodash.reduce": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/lodash.reduce/-/lodash.reduce-4.6.0.tgz",
......@@ -4019,6 +4095,11 @@
"lodash.escape": "3.2.0"
}
},
"long-timeout": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/long-timeout/-/long-timeout-0.1.1.tgz",
"integrity": "sha1-lyHXiLR+C8taJMLivuGg2lXatRQ="
},
"lru-cache": {
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz",
......@@ -4261,6 +4342,11 @@
"xtend": "4.0.1"
}
},
"moment": {
"version": "2.20.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.20.1.tgz",
"integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
......@@ -4689,6 +4775,43 @@
"integrity": "sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=",
"dev": true
},
"passport": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/passport/-/passport-0.4.0.tgz",
"integrity": "sha1-xQlWkTR71a07XhgCOMORTRbwWBE=",
"requires": {
"passport-strategy": "1.0.0",
"pause": "0.0.1"
}
},
"passport-jwt": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/passport-jwt/-/passport-jwt-3.0.1.tgz",
"integrity": "sha1-5Pcnba2L0lHUPG/DiIMTC5YycvY=",
"requires": {
"jsonwebtoken": "7.4.3",
"passport-strategy": "1.0.0"
},
"dependencies": {
"jsonwebtoken": {
"version": "7.4.3",
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-7.4.3.tgz",
"integrity": "sha1-d/UCHeBYtgWheD+hKD6ZgS5kVjg=",
"requires": {
"joi": "6.10.1",
"jws": "3.1.4",
"lodash.once": "4.1.1",
"ms": "2.0.0",
"xtend": "4.0.1"
}
}
}
},
"passport-strategy": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz",
"integrity": "sha1-tVOaqPwiWj0a0XlHbd8ja0QPUuQ="
},
"path-browserify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz",
......@@ -4748,6 +4871,11 @@
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"pause": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/pause/-/pause-0.0.1.tgz",
"integrity": "sha1-HUCLP9t2kjuVQ9lvtMnf1TXZy10="
},
"pause-stream": {
"version": "0.0.11",
"resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz",
......@@ -6170,6 +6298,21 @@
"repeat-string": "1.6.1"
}
},
"topo": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/topo/-/topo-1.1.0.tgz",
"integrity": "sha1-6ddRYV0buH3IZdsYL6HKCl71NtU=",
"requires": {
"hoek": "2.16.3"
},
"dependencies": {
"hoek": {
"version": "2.16.3",
"resolved": "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz",
"integrity": "sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0="
}
}
},
"tough-cookie": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz",
......@@ -6484,8 +6627,7 @@
"uuid": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz",
"integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==",
"dev": true
"integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g=="
},
"uws": {
"version": "0.14.5",
......
......@@ -35,6 +35,8 @@
"mocha": "mocha test/ --recursive --exit"
},
"dependencies": {
"@feathersjs/authentication": "^2.1.1",
"@feathersjs/authentication-jwt": "^2.0.0",
"@feathersjs/configuration": "^1.0.2",
"@feathersjs/errors": "^3.2.2",
"@feathersjs/express": "^1.1.2",
......
......@@ -8,6 +8,11 @@
<input type="password" name="password" id="password">
<input type="submit" value="Create site">
</form>
<form action="private" id="private">
<input type="submit" value="Get private data">
</form>
<script src="js/script.js"></script>
</body>
</html>
......@@ -9,6 +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 middleware = require('./middleware')
const services = require('./services')
......@@ -32,6 +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());
// Configure other middleware (see `middleware/index.js`)
app.configure(middleware)
......
const keys = require('./keys/keys.service.js');
const authorize = require('./authorize/authorize.service.js');
const private = require('./private/private.service.js');
module.exports = function (app) {
app.configure(keys);
app.configure(authorize);
app.configure(private);
};
/* eslint-disable no-unused-vars */
class Service {
constructor (options) {
this.options = options || {};
}
async find (params) {
return ['dit is alle data'];
}
async get (id, params) {
return {
id, text: `A new message with ID: ${id}!`
};
}
async create (data, params) {
if (Array.isArray(data)) {
return await Promise.all(data.map(current => this.create(current)));
}
return data;
}
async update (id, data, params) {
return data;
}
async patch (id, data, params) {
return data;
}
async remove (id, params) {
return { id };
}
}
module.exports = function (options) {
return new Service(options);
};
module.exports.Service = Service;
const authentication = require('@feathersjs/authentication');
module.exports = {
before: {
all: [],
find: [
authentication.hooks.authenticate('jwt')
],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
// Initializes the `private` service on path `/private`
const createService = require('./private.class.js');
const hooks = require('./private.hooks');
module.exports = function (app) {
const paginate = app.get('paginate');
const options = {
name: 'private',
paginate
};
// Initialize our service with any options it requires
app.use('/private', createService(options));
// Get our initialized service so that we can register hooks and filters
const service = app.service('private');
service.hooks(hooks);
};
const assert = require('assert');
const app = require('../../server/app');
describe('\'private\' service', () => {
it('registered the service', () => {
const service = app.service('private');
assert.ok(service, 'Registered the service');
});
});
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