Search code examples
azureazure-application-insights

Azure App Insights -- How to get the user ID or email for an AAD authenticated visitor?


I have an Azure Static Web App and App Insights running using the standard set of telemetry code found here: https://github.com/Microsoft/ApplicationInsights-JS#snippet-setup-ignore-if-using-npm-setup

I am wondering how I can get the user details using my AAD-protected website? My website generates authentication information that an individual can access by tacking on /.auth/me to the end of the website URL, which looks like, and I am wondering if this is possibly a way to do it.

{
  "clientPrincipal": {
    "identityProvider": "aad",
    "userId": "xxxx",
    "userDetails": "xxxx",
    "userRoles": [
      "authenticated",
      "anonymous"
    ]
  }
}

In related posts, this thread seems fairly related to my interests but I cannot make much of anything from the discussion: Azure - App Insights - how to track the logged-in Username in Auth Id?


Solution

  • I assume that you want user id details using your AAD-protected website . Here are the steps to know the user ID and details:

    Go to Application insight > View Application Insights data. enter image description here

    Go to users > Click on View more insights

    enter image description here

    After scroll down to select as below enter image description here

    As Selected Authentication user ID > Click on User Timeline to check the details of USER. enter image description here

    For more information Please refer this similar So thread.