@azure-rest/maps-route
Version:
A client library for Azure Maps maps-route
44 lines • 2.14 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = MapsRoute;
const tslib_1 = require("tslib");
const core_auth_1 = require("@azure/core-auth");
const maps_common_1 = require("@azure/maps-common");
const index_js_1 = tslib_1.__importDefault(require("./generated/index.js"));
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
function MapsRoute(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, index_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, index_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, index_js_1.default)(credential, options);
}
//# sourceMappingURL=mapsRoute.js.map