@azure/eventgrid
Version:
An isomorphic client library for the Azure Event Grid service.
20 lines • 1.43 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { DEFAULT_API_VERSION } from "./constants.js";
import { sha256Hmac } from "./cryptoHelpers.js";
import { dateToServiceTimeString } from "./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.
*/
export async function generateSharedAccessSignature(endpointUrl, credential, expiresOnUtc, options) {
const expiresOnString = dateToServiceTimeString(expiresOnUtc);
const unsignedSas = `r=${encodeURIComponent(`${endpointUrl}?apiVersion=${(options === null || options === void 0 ? void 0 : options.apiVersion) || DEFAULT_API_VERSION}`)}&e=${encodeURIComponent(expiresOnString)}`;
return sha256Hmac(credential.key, unsignedSas).then((digest) => `${unsignedSas}&s=${encodeURIComponent(digest)}`);
}
//# sourceMappingURL=generateSharedAccessSignature.js.map