@azure-rest/maps-search
Version:
A generated SDK for MapsSearchClient.
40 lines • 1.92 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { isSASCredential, isTokenCredential } from "@azure/core-auth";
import { createMapsClientIdPolicy } from "@azure/maps-common";
import createClient from "./generated/index.js";
import { bearerTokenAuthenticationPolicy } from "@azure/core-rest-pipeline";
export default function MapsSearch(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=MapsSearch.js.map