Create an authorization token for CosmosDB in a Postman Pre-test Script
This file contains 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
var now = new Date().toUTCString(); | |
pm.environment.set("utcDate", now); | |
var verb = 'GET'; | |
var resourceType = pm.variables.get("resourceType"); | |
var resourceId = pm.variables.get("resourceId"); | |
var text = (verb || "").toLowerCase() + "\n" + (resourceType || "").toLowerCase() + "\n" + (resourceId || "") + "\n" + now.toLowerCase() + "\n" + "" + "\n"; | |
var key = CryptoJS.enc.Base64.parse(pm.variables.get("masterKey")); | |
var signature = CryptoJS.HmacSHA256(text, key).toString(CryptoJS.enc.Base64); | |
var MasterToken = "master"; | |
var TokenVersion = "1.0"; | |
var authToken = encodeURIComponent("type=" + MasterToken + "&ver=" + TokenVersion + "&sig=" + signature); | |
pm.environment.set("authToken", authToken); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
muito obrigado!