Skip to content

Commit

Permalink
Merge pull request #2 from frankiethekneeman/feature/Expiration
Browse files Browse the repository at this point in the history
Expire Keys in the HawkAuthenticator, also add expiration data to Ser…
  • Loading branch information
frankiethekneeman committed Nov 2, 2015
2 parents c655eb9 + 881c716 commit b43e8a7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 5 additions & 1 deletion demo/providerDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ var ServerosServiceProvider = require('../src/classes/ServerosServiceProvider')
, authenticator = new HawkAuthenticator();
;

application.use('/authenticate', bodyParser.json());
application.use(bodyParser.json());
application.post('/authenticate', provider.expressValidator(authenticator.credentialsAccepter()));
application.use(authenticator.expressAuthorizer());
application.get('/test', function(req, res, next) {
res.json({'Authed As': req.authedAs, 'Auth Data': req.authData});
});
application.post('/test', function(req, res, next) {
res.send();
console.log({'Authed As': req.authedAs, 'Auth Data': req.authData, 'Payload': req.body});
});
var server = application.listen(3501, 'localhost', function () {
var host = server.address().address;
var port = server.address().port;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serveros",
"version": "0.2.3",
"version": "0.2.4",
"description": "Auth for networks of applications.",
"repository": {
"type": "git",
Expand Down
9 changes: 7 additions & 2 deletions src/classes/HawkAuthenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ HawkAuthenticator.prototype = {
Hawk.server.authenticate(req, function(id, callback) {
that.storage.retrieve(id, function(credentials) {
if (!credentials) {
callback("No Credentials Found.");
return;
callback("No Credentials Found.");
return;
}
if (Date.now() < credentials.expires) {
that.storage.purge(id, function() {
if (callback) callback("Credentials Expired");
});
}
var hawkCredentials = {
key: credentials.secret
Expand Down
1 change: 1 addition & 0 deletions src/classes/ServerosConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ ServerosConsumer.prototype.authorize = function(serviceLocation, ticket, callbac
, id: ticket.id
, key: ticket.secret
, algorithm: ticket.hash
, expires: ticket.expires
});
}
});
Expand Down

0 comments on commit b43e8a7

Please sign in to comment.