Skip to content

Commit

Permalink
Merge pull request #202 from hicsail/tokenActive
Browse files Browse the repository at this point in the history
Token active/deactive
  • Loading branch information
gregfrasco committed Aug 28, 2018
2 parents ed81fac + bcc7876 commit 0264bbb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
38 changes: 38 additions & 0 deletions server/api/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ const register = function (server,serverOptions) {
return await Token.create(request.payload);
}
});

server.route({
method: 'PUT',
path: '/api/tokens/{id}/active',
options: {
auth: {
strategies: ['simple','session','token']
}
},
handler: async function (request,h) {

console.log('token');

const id = request.params.id;

return await Token.findByIdAndUpdate(id,{
$set: {
isActive: true
}
});
}
});

server.route({
method:'PUT',
path:'/api/tokens/{id}/deactive',
options: {
auth: {
strategies: ['simple','session','token']
}
},
handler: async function (request,h) {

const id = request.params.id;

return await Token.findByIdAndUpdate(id,{ $set: { isActive: false } });
}
});
};

module.exports = {
Expand Down
4 changes: 4 additions & 0 deletions server/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const register = function (server, options) {
return { isValid: false };
}

if (!token.isActive) {
return { isValid: false };
}

if (!confirmTokenPermission(request,token)) {
throw Boom.forbidden('Insufficient token permissions');
}
Expand Down
4 changes: 4 additions & 0 deletions server/models/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Token.payload = Joi.object({
permission: Joi.any()
});

Token.isActivePayload = Joi.object({
isActive: Joi.boolean().required()
});

Token.routes = Hoek.applyToDefaults(AnchorModel.routes, {
create: {
disabled: false,
Expand Down

0 comments on commit 0264bbb

Please sign in to comment.