Azure Maps - where do I find my tokenServiceUrl

JPSac-3841 0 Reputation points
2025-09-11T00:36:54.4466667+00:00

I have created my azure map account, resource, etc. I am trying to use a webpage in HTML to access a SAS token for the map authentication:

// URL to your authentication service that retrieves an Microsoft Entra ID Token.

	// example:

    var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';

I have not been able to find what my URL is or where it is located in the Azure Map Portal. I reviewed many documents online to try to figure this out. I assume this is something simple I am just missing. I appreciate any assistance.

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
{count} votes

1 answer

Sort by: Most helpful
  1. Manas Mohanty 11,700 Reputation points Microsoft External Staff Moderator
    2025-09-15T06:12:18.22+00:00

    Hi JPSac-3841,

    Sorry for the late response.

    Steps to use SAS token with keyvault and User assigned identity are below

    1. Create a key vault.
    2. Create a user-assigned managed identity.
    3. Assign Azure role-based access control (RBAC) Azure Maps Data Reader role to the user-assigned managed identity.
    4. Create an Azure Maps account with a Cross Origin Resource Sharing (CORS) configuration, and attach the user-assigned managed identity.
    5. Create and save a SAS token in the Azure Key Vault.
    6. Retrieve the SAS token secret from the key vault.
    7. Create an Azure Maps REST API request that uses the SAS token.

    Reference -

    1. https://github.com/azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.maps/maps-use-sas
    2. https://free.blessedness.top/en-us/azure/azure-maps/how-to-secure-sas-app#example-scenario-sas-token-secure-storage
    3. Using CLI
    az login
    az provider register --namespace Microsoft.KeyVault
    az provider register --namespace Microsoft.ManagedIdentity
    az provider register --namespace Microsoft.Maps
    
    $id = $(az rest --method GET --url 'https://graph.microsoft.com/v1.0/me?$select=id' --headers 'Content-Type=application/json' --query "id")
    
    az group create --name <group-name> --location "East US"
    $outputs = $(az deployment group create --name ExampleDeployment --resource-group <group-name> --template-file "./prereq.azuredeploy.json" --parameters objectId=$id --query "[properties.outputs.keyVaultName.value, properties.outputs.userAssignedIdentityPrincipalId.value, properties.outputs.userIdentityResourceId.value]" --output tsv)
    az deployment group create --name ExampleDeployment --resource-group <group-name> --template-file "./azuredeploy.json" --parameters keyVaultName="$($outputs[0])" userAssignedIdentityPrincipalId="$($outputs[1])" userAssignedIdentityResourceId="$($outputs[2])" allowedOrigins="['http://localhost']" allowedRegions="['eastus', 'westus2', 'westcentralus']" maxRatePerSecond="10"
    $secretId = $(az keyvault secret list --vault-name $outputs[0] --query "[? contains(name,'map')].id" --output tsv)
    $sasToken = $(az keyvault secret show --id "$secretId" --query "value" --output tsv)
    
    az rest --method GET --url 'https://us.atlas.microsoft.com/search/address/json?api-version=1.0&query=1 Microsoft Way, Redmond, WA 98052' --headers "Authorization=jwt-sas $($sasToken)" --query "results[].address"
    
    

    Using Python Client

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.maps import AzureMapsManagementClient
    
    """
    # PREREQUISITES
        pip install azure-identity
        pip install azure-mgmt-maps
    # USAGE
        python account_list_sas.py
    
        Before run the sample, please set the values of the client ID, tenant ID and client secret
        of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
        AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
        https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
    """
    
    
    def main():
        client = AzureMapsManagementClient(
            credential=DefaultAzureCredential(),
            subscription_id="21a9967a-e8a9-4656-a70b-96ff1c4d05a0",
        )
    
        response = client.accounts.list_sas(
            resource_group_name="myResourceGroup",
            account_name="myMapsAccount",
            maps_account_sas_parameters={
                "expiry": "2017-05-24T11:42:03.1567373Z",
                "maxRatePerSecond": 500,
                "principalId": "e917f87b-324d-4728-98ed-e31d311a7d65",
                "regions": ["eastus"],
                "signingKey": "primaryKey",
                "start": "2017-05-24T10:42:03.1567373Z",
            },
        )
        print(response)
    
    
    # x-ms-original-file: specification/maps/resource-manager/Microsoft.Maps/stable/2023-06-01/examples/AccountListSAS.json
    if __name__ == "__main__":
        main()
    
    

    Reference - https://free.blessedness.top/en-us/rest/api/maps-management/accounts/list-sas?view=rest-maps-management-2023-06-01&tabs=Python#examples

    Sample SAS token usage

    async function getData(url = 'https://us.atlas.microsoft.com/search/address/json?api-version=1.0&query=1 Microsoft Way, Redmond, WA 98052') {
      const response = await fetch(url, {
        method: 'GET',
        mode: 'cors',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'jwt-sas <your SAS token>',
        }
      });
      return response.json(); // parses JSON response into native JavaScript objects
    }
    
    postData('https://us.atlas.microsoft.com/search/address/json?api-version=1.0&query=1 Microsoft Way, Redmond, WA 98052')
      .then(data => {
        console.log(data); // JSON data parsed by `data.json()` call
      });
    
    
    

    Hope it helps.

    Thank you

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.