@azure-rest/maps-render
Version:
A generated SDK for MapsRenderClient.
44 lines • 2.2 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = MapsRender;
const tslib_1 = require("tslib");
const core_auth_1 = require("@azure/core-auth");
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
const maps_common_1 = require("@azure/maps-common");
const mapsRenderClient_js_1 = tslib_1.__importDefault(require("./generated/mapsRenderClient.js"));
function MapsRender(credential, clientIdOrOptions = {}, maybeOptions = {}) {
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
/**
* maps service requires a header "ms-x-client-id", which is different from the standard Microsoft Entra ID.
* So we need to do our own implementation.
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
*/
if ((0, core_auth_1.isTokenCredential)(credential)) {
const clientId = typeof clientIdOrOptions === "string" ? clientIdOrOptions : "";
if (!clientId) {
throw Error("Client id is needed for TokenCredential");
}
const client = (0, mapsRenderClient_js_1.default)(undefined, options);
client.pipeline.addPolicy((0, core_rest_pipeline_1.bearerTokenAuthenticationPolicy)({
credential,
scopes: "https://atlas.microsoft.com/.default",
}));
client.pipeline.addPolicy((0, maps_common_1.createMapsClientIdPolicy)(clientId));
return client;
}
if ((0, core_auth_1.isSASCredential)(credential)) {
const client = (0, mapsRenderClient_js_1.default)(undefined, options);
client.pipeline.addPolicy({
name: "mapsSASCredentialPolicy",
async sendRequest(request, next) {
request.headers.set("Authorization", `jwt-sas ${credential.signature}`);
return next(request);
},
});
return client;
}
return (0, mapsRenderClient_js_1.default)(credential, options);
}
//# sourceMappingURL=mapsRender.js.map