Created
December 1, 2019 18:18
-
-
Save lfalck/a0294f86080a7960734afa64e2d298b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createServiceBusOrEventHubsSASToken(resourceUri, sasKeyName, sasKey) { | |
if (!resourceUri || !sasKeyName || !sasKey) { | |
throw "Missing required parameter"; | |
} | |
const encoded = encodeURIComponent(resourceUri); | |
const now = new Date(); | |
const minute = 60; | |
const ttl = Math.round(now.getTime() / 1000) + minute; | |
const signature = encoded + '\n' + ttl; | |
const hash = CryptoJS.HmacSHA256(signature, sasKey) | |
.toString(CryptoJS.enc.Base64); | |
return 'SharedAccessSignature sr=' + encoded + '&sig=' + | |
encodeURIComponent(hash) + '&se=' + ttl + '&skn=' + sasKeyName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment