UNPKG

@azure-rest/maps-render

Version:
40 lines 1.93 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { isSASCredential, isTokenCredential } from "@azure/core-auth"; import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline"; import { createMapsClientIdPolicy } from "@azure/maps-common"; import createClient from "./generated/mapsRenderClient.js"; export default 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 (isTokenCredential(credential)) { const clientId = typeof clientIdOrOptions === "string" ? clientIdOrOptions : ""; if (!clientId) { throw Error("Client id is needed for TokenCredential"); } const client = createClient(undefined, options); client.pipeline.addPolicy(bearerTokenAuthenticationPolicy({ credential, scopes: "https://atlas.microsoft.com/.default", })); client.pipeline.addPolicy(createMapsClientIdPolicy(clientId)); return client; } if (isSASCredential(credential)) { const client = createClient(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 createClient(credential, options); } //# sourceMappingURL=mapsRender.js.map