UNPKG

@azure/eventgrid

Version:
23 lines 1.61 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.generateSharedAccessSignature = generateSharedAccessSignature; const constants_js_1 = require("./constants.js"); const cryptoHelpers_js_1 = require("./cryptoHelpers.js"); const util_js_1 = require("./util.js"); /** * Generate a shared access signature, which allows a client to send events to an Event Grid Topic or Domain for a limited period of time. This * function may only be called when the EventGridPublisherClient was constructed with a KeyCredential instance. * * @param endpointUrl - The endpoint for the topic or domain you wish to generate a shared access signature for. * @param credential - The credential to use when generating the shared access signatrue. * @param expiresOn - The time at which the shared access signature is no longer valid. * @param options - Options to control how the signature is generated. */ async function generateSharedAccessSignature(endpointUrl, credential, expiresOnUtc, options) { const expiresOnString = (0, util_js_1.dateToServiceTimeString)(expiresOnUtc); const unsignedSas = `r=${encodeURIComponent(`${endpointUrl}?apiVersion=${(options === null || options === void 0 ? void 0 : options.apiVersion) || constants_js_1.DEFAULT_API_VERSION}`)}&e=${encodeURIComponent(expiresOnString)}`; return (0, cryptoHelpers_js_1.sha256Hmac)(credential.key, unsignedSas).then((digest) => `${unsignedSas}&s=${encodeURIComponent(digest)}`); } //# sourceMappingURL=generateSharedAccessSignature.js.map