/**
* Util to base64 decode a string that has been encoded using the
* HttpServerUtility.UrlTokenEncode method. See:
* {@link https://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urltokenencode(v=vs.110).aspx}
*
* Note: do not include this util in the web build. This will cause webpack to include large
* polyfills for the NodeJS Buffer Class.
*
* @param {string} data The data to decode
* @returns {Buffer} A NodeJS buffer with the decoded data
*/
function msUrlTokenDecode(data) {
let processed = data
// replace - with +
.replace(/-/g, '+')
// replace _ with /
.replace(/_/g, '/');
// Add '=' character to processedData to be % 4
switch (processed.length % 4) {
case 2:
processed += '==';
break;
case 3:
processed += '=';
break;
default:
break;
}
return Buffer.from(processed, 'base64');
}
export default msUrlTokenDecode;