ampache_react/app/utils/ampache.js
Phyks (Lucas Verney) d8a7d4f66a Rework webplayer
Full rework of webplayer. Webplayer is back to its previous working
state, and ready for further improvements.
2016-08-10 23:50:23 +02:00

33 lines
775 B
JavaScript

/**
* Collection of helper function that are Ampache specific.
*/
// NPM imports
import jsSHA from "jssha";
/**
* Build an HMAC token for authentication against Ampache API.
*
* @param password User password to derive HMAC from.
* @return An object with the generated HMAC and time used.
*
* @remark This builds an HMAC as expected by Ampache API, which is not a
* standard HMAC.
*/
export function buildHMAC(password) {
const time = Math.floor(Date.now() / 1000);
let shaObj = new jsSHA("SHA-256", "TEXT");
shaObj.update(password);
const key = shaObj.getHash("HEX");
shaObj = new jsSHA("SHA-256", "TEXT");
shaObj.update(time + key);
return {
time: time,
passphrase: shaObj.getHash("HEX"),
};
}