e9d925334c
We will share it between tests and a middleware to parse the token.
30 lines
701 B
JavaScript
30 lines
701 B
JavaScript
/**
|
|
* @param {String} token might match the following pattern: {user}@{tpl_id}@{token}:{cache_buster}
|
|
*/
|
|
function parse(token) {
|
|
var signer, cacheBuster;
|
|
|
|
var tokenSplit = token.split(':');
|
|
|
|
token = tokenSplit[0];
|
|
if (tokenSplit.length > 1) {
|
|
cacheBuster = tokenSplit[1];
|
|
}
|
|
|
|
tokenSplit = token.split('@');
|
|
if ( tokenSplit.length > 1 ) {
|
|
signer = tokenSplit.shift();
|
|
if ( tokenSplit.length > 1 ) {
|
|
/*var template_hash = */tokenSplit.shift(); // unused
|
|
}
|
|
token = tokenSplit.shift();
|
|
}
|
|
|
|
return {
|
|
token: token,
|
|
signer: signer,
|
|
cacheBuster: cacheBuster
|
|
};
|
|
}
|
|
module.exports.parse = parse;
|