Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create an authorization token for CosmosDB in a Postman Pre-test Script
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);
@calfersantos

This comment has been minimized.

Copy link

@calfersantos calfersantos commented Oct 9, 2019

muito obrigado!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment