In Azure APIM Management API, how to programmatically create a SAS token?

Chirag Chhajed 0 Reputation points

User's image

I am trying to automate the process of access token generation. in this article, the code sample uses C# but I am using nodejs. Token generated from azure portal works but token generated from this function gives a 401 Unauthorized error.

I want to access token for using this api

code in nodejs:

import crypto from "crypto";

const generateSasToken = (id: string, key: string, expiry: Date): string => {
  const stringToSign = `${id}\n${expiry.toISOString()}`;
  const signature = crypto
    .createHmac("sha512", Buffer.from(key, "base64"))

  return `SharedAccessSignature uid=${id}&ex=${expiry.toISOString().replace(/\.\d+Z$/, ".0000000Z")}&sn=${signature}`;

export { generateSasToken };

    new Date( + 10 * 24 * 60 * 60 * 1000)

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,728 questions
{count} votes