keymetrics-api
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -26,2 +26,3 @@ 'use strict'; | ||
this.http = new Http(); | ||
this.refresh_token = opts.token || ''; | ||
@@ -49,4 +50,5 @@ this.bus.on('auth:ready', function (data) { | ||
cb = token; | ||
token = this.token || ''; | ||
token = this.refresh_token || ''; | ||
} | ||
cb = cb || function(){}; | ||
@@ -69,2 +71,17 @@ var post = this.http | ||
Authenticate.prototype.checkExpiration = function() { | ||
var self = this; | ||
var date = new Date(this.expire_at) | ||
if (Date.now() - date.getTime() < 10 * 60000) | ||
this.refresh(function(err, data) { | ||
if (err) { | ||
self.bus.emit('error:auth', { msg: 'Refeshing token failed, maybe invalid/revoked token ?', err: err }); | ||
return err; | ||
} | ||
self.bus.emit('auth:ready', data); | ||
}); | ||
}; | ||
/** | ||
@@ -91,2 +108,6 @@ * Starts the authentication process | ||
self.bus.emit('auth:ready', data); | ||
// start watcher | ||
self.watcher = setInterval(self.checkExpiration.bind(self), 60000); | ||
return cb(null, data); | ||
@@ -132,4 +153,5 @@ }) | ||
}); | ||
clearInterval(self.watcher); | ||
}; | ||
module.exports = Authenticate; |
{ | ||
"name": "keymetrics-api", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Keymetrics API Wrapper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2781713
19696