
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
@azure-rest/maps-geolocation
Advanced tools
Azure Maps Geolocation Client
**If you are not familiar with our REST client, please spend 5 minutes to take a look at our REST client docs to use this library, the REST client provides a light-weighted & developer friendly way to call azure rest api
Key links:
If you use Azure CLI, replace <resource-group-name>
and <map-account-name>
of your choice, and select a proper pricing tier based on your needs via the <sku-name>
parameter. Please refer to Azure Maps Reference for Azure CLI for more details.
az maps account create --resource-group <resource-group-name> --name <map-account-name> --sku <sku-name>
@azure-rest/maps-geolocation
packageInstall the Azure Maps Geolocation REST client REST client library for JavaScript with npm
:
npm install @azure-rest/maps-geolocation
MapsGeolocationClient
You'll need a credential
instance for authentication when creating the MapsGeolocationClient
instance used to access the Azure Maps render APIs. You can use either a Microsoft Entra ID credential or an Azure subscription key to authenticate. For more information on authentication, see Authentication with Azure Maps.
To use an Microsoft Entra ID token credential, provide an instance of the desired credential type obtained from the @azure/identity library.
To authenticate with Microsoft Entra ID, you must first npm
install @azure/identity
After setup, you can choose which type of credential from @azure/identity
to use.
As an example, DefaultAzureCredential
can be used to authenticate the client.
You'll need to register the new Microsoft Entra ID application and grant access to Azure Maps by assigning the required role to your service principal. For more information, see Host a daemon on non-Azure resources. Set the values of the client ID, tenant ID, and client secret of the Microsoft Entra ID application as environment variables:
AZURE_CLIENT_ID
, AZURE_TENANT_ID
, AZURE_CLIENT_SECRET
.
You will also need to specify the Azure Maps resource you intend to use by specifying the clientId
in the client options.
The Azure Maps resource client id can be found in the Authentication sections in the Azure Maps resource. Please refer to the documentation on how to find it.
import { DefaultAzureCredential } from "@azure/identity";
import MapsGeolocation from "@azure-rest/maps-geolocation";
const credential = new DefaultAzureCredential();
const client = MapsGeolocation(credential, "<maps-account-client-id>");
You can authenticate with your Azure Maps Subscription Key. Please install the"@azure/core-auth"package:
npm install @azure/core-auth
import { AzureKeyCredential } from "@azure/core-auth";
import MapsGeolocation from "@azure-rest/maps-geolocation";
const credential = new AzureKeyCredential("<subscription-key>");
const client = MapsGeolocation(credential);
Shared access signature (SAS) tokens are authentication tokens created using the JSON Web token (JWT) format and are cryptographically signed to prove authentication for an application to the Azure Maps REST API.
You can get the SAS token using AzureMapsManagementClient.accounts.listSas
from "@azure/arm-maps" package. Please follow the section Create and authenticate a AzureMapsManagementClient
to setup first.
Second, follow Managed identities for Azure Maps to create a managed identity for your Azure Maps account. Copy the principal ID (object ID) of the managed identity.
Third, you will need to install"@azure/core-auth"package to use AzureSASCredential
:
npm install @azure/core-auth
Finally, you can use the SAS token to authenticate the client:
import { DefaultAzureCredential } from "@azure/identity";
import { AzureMapsManagementClient } from "@azure/arm-maps";
import { AzureSASCredential } from "@azure/core-auth";
import MapsGeolocation from "@azure-rest/maps-geolocation";
const subscriptionId = "<subscription ID of the map account>";
const resourceGroupName = "<resource group name of the map account>";
const accountName = "<name of the map account>";
const mapsAccountSasParameters = {
start: "<start time in ISO format>", // e.g. "2023-11-24T03:51:53.161Z"
expiry: "<expiry time in ISO format>", // maximum value to start + 1 day
maxRatePerSecond: 500,
principalId: "<principle ID (object ID) of the managed identity>",
signingKey: "primaryKey",
};
const credential = new DefaultAzureCredential();
const managementClient = new AzureMapsManagementClient(credential, subscriptionId);
const { accountSasToken } = await managementClient.accounts.listSas(
resourceGroupName,
accountName,
mapsAccountSasParameters,
);
if (accountSasToken === undefined) {
throw new Error("No accountSasToken was found for the Maps Account.");
}
const sasCredential = new AzureSASCredential(accountSasToken);
const client = MapsGeolocation(sasCredential);
MapsGeolocationClient
is the primary interface for developers using the Azure Maps Geolocation client library. Explore the methods on this client object to understand the different features of the Azure Maps Geolocation service that you can access.
You can get the country code from a IP address:
import { DefaultAzureCredential } from "@azure/identity";
import MapsGeolocation, { isUnexpected } from "@azure-rest/maps-geolocation";
const credential = new DefaultAzureCredential();
const client = MapsGeolocation(credential, "<maps-account-client-id>");
const result = await client.path("/geolocation/ip/{format}", "json").get({
queryParameters: { ip: "2001:4898:80e8:b::189" },
});
if (isUnexpected(result)) {
throw result.body.error;
}
if (!result.body.countryRegion) {
throw new Error("No country region was found for the IP address.");
}
console.log(`The country code for the IP address is ${result.body.countryRegion.isoCode}`);
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment variable to info
. Alternatively, logging can be enabled at runtime by calling setLogLevel
in the @azure/logger
:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.
FAQs
A generated SDK for MapsGeolocationClient.
We found that @azure-rest/maps-geolocation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.