@azure/eventgrid
Version:
An isomorphic client library for the Azure Event Grid service.
38 lines • 1.38 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.eventGridCredentialPolicyName = void 0;
exports.eventGridCredentialPolicy = eventGridCredentialPolicy;
const util_js_1 = require("./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.
*/
exports.eventGridCredentialPolicyName = "eventGridCredentialPolicy";
/**
* A concrete implementation of an AzureKeyCredential policy
* using the appropriate header for Event Grid
*/
function eventGridCredentialPolicy(credential) {
return {
name: exports.eventGridCredentialPolicyName,
async sendRequest(request, next) {
if ((0, util_js_1.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