@azure/eventgrid
Version:
An isomorphic client library for the Azure Event Grid service.
34 lines • 1.19 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { isKeyCredentialLike } from "./util.js";
/**
* The name of the header to include when a Shared Key is used for authentication.
*/
const API_KEY_HEADER_NAME = "aeg-sas-key";
/**
* The name of the header to include when Shared Access Signature is used for authentication.
*/
const SAS_TOKEN_HEADER_NAME = "aeg-sas-token";
/**
* The programmatic identifier of the eventGridCredentialPolicy.
*/
export const eventGridCredentialPolicyName = "eventGridCredentialPolicy";
/**
* A concrete implementation of an AzureKeyCredential policy
* using the appropriate header for Event Grid
*/
export function eventGridCredentialPolicy(credential) {
return {
name: eventGridCredentialPolicyName,
async sendRequest(request, next) {
if (isKeyCredentialLike(credential)) {
request.headers.set(API_KEY_HEADER_NAME, credential.key);
}
else {
request.headers.set(SAS_TOKEN_HEADER_NAME, credential.signature);
}
return next(request);
},
};
}
//# sourceMappingURL=eventGridAuthenticationPolicy.js.map