changed the key used to store tunnel tokens
This commit is contained in:
parent
61018d9303
commit
49d5e5296a
|
@ -27,6 +27,22 @@ module.exports.create = function (deps, config) {
|
||||||
return fs.writeFileAsync(tokensPath, JSON.stringify(tokens), 'utf8');
|
return fs.writeFileAsync(tokensPath, JSON.stringify(tokens), 'utf8');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
, _makeKey: function (token) {
|
||||||
|
// We use a stripped down version of the token contents so that if the token is
|
||||||
|
// re-issued the nonce and the iat and any other less important things are different
|
||||||
|
// we don't save essentially duplicate tokens multiple times.
|
||||||
|
var parsed = JSON.parse((new Buffer(token.split('.')[1], 'base64')).toString());
|
||||||
|
var stripped = {};
|
||||||
|
['aud', 'iss', 'domains'].forEach(function (key) {
|
||||||
|
if (parsed[key]) {
|
||||||
|
stripped[key] = parsed[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
stripped.domains.sort();
|
||||||
|
|
||||||
|
var hash = require('crypto').createHash('sha256');
|
||||||
|
return hash.update(JSON.stringify(stripped)).digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
, all: function () {
|
, all: function () {
|
||||||
var tokens = storage._read();
|
var tokens = storage._read();
|
||||||
|
@ -34,15 +50,19 @@ module.exports.create = function (deps, config) {
|
||||||
return tokens[key];
|
return tokens[key];
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
, save: function (result) {
|
, save: function (token) {
|
||||||
var tokens = storage._read();
|
return PromiseA.resolve().then(function () {
|
||||||
tokens[result.jwt] = result;
|
var curTokens = storage._read();
|
||||||
storage._write(tokens);
|
curTokens[storage._makeKey(token)] = token;
|
||||||
|
return storage._write(curTokens);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
, del: function (id) {
|
, del: function (token) {
|
||||||
var tokens = storage._read();
|
return PromiseA.resolve().then(function () {
|
||||||
delete tokens[id];
|
var curTokens = storage._read();
|
||||||
storage._write(tokens);
|
delete curTokens[storage._makeKey(token)];
|
||||||
|
return storage._write(curTokens);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue