AzureMaps authentication with subscriptionKey

Luciano Martín López 0 Reputation points
2024-02-02T14:42:36.0066667+00:00

Hi, I use Azure Maps in a React app, and for authentication, I use the react-azure-maps npm module. However, in a production environment, it throws this error:

  "error": {
    "code": "Unauthorized",
    "message": "Bearer realm=\"https://atlas.microsoft.com/\", SharedKey realm=\"https://atlas.microsoft.com/\"",
    "target": "WWW-Authenticate",
    "details": [ ]
  }
}

I understand that it is asking for a token, which is why I think I am passing my subscription key incorrectly. The methos i use to declare the subscriptionKey is :


const option: IAzureMapOptions = {
  authOptions: {
    authType: AuthenticationType.subscriptionKey,
    subscriptionKey:"<My subscriptionKey>" //</> Your subscription key
  },
};

Is this method correct?

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

1 answer

Sort by: Most helpful
  1. rbrundritt 20,836 Reputation points Microsoft Employee Moderator
    2024-02-05T19:03:53.8366667+00:00

    You code looks correct. Make sure that the options are being passed into the map object. For example: <AzureMap options={option}>

    Verify your subscription key is correct, it's pretty easy to miss a character when copy/pasting, or accidentally add a space or additional character. Also make sure you are passing in your primary or secondary key and not your client ID.

    Take a look at the network tab of the browser dev tools and look at some of the requests to https://atlas.microsoft.com and take a look at the URL's and headers to see if there is a subscription-key property. This should usually be in the request URL but could be a query parameter on the URL itself. If you don't see one of these, then it's likely the map isn't getting your options and is using its defaults.

    1 person found this answer helpful.

Your answer

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