locked
how can i get app name with appid with c#? RRS feed

  • Question

  • I have Web api which is used by may applications. Now for some analytics purpose  need the app name which is calling my web api.

    All applications which are calling my web api are registered in AAD. All clients call my web api with a application generated token. I can get the app id from claims.

    I had a solution but i dont want to maintain appid-appname in my config file as these will be changed from environment to environment and its hard to maintain for growing number of clients.

    Sunday, January 13, 2019 5:29 AM

Answers

  • You can try adding "app_displayname" customized claim to the token to get the application name.  Please refer to documentation to customize claims emitted in tokens for a specific app in a tenant, however, this feature is currently in Preview.

    Tuesday, February 5, 2019 11:04 PM

All replies

  • You can access the Application ID and Secret using Azure Key Vault.

    //add these using statements using Microsoft.Azure.KeyVault; using System.Web.Configuration; // I put my GetToken method in a Utils class. Change for wherever you placed your method. var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(Utils.GetToken)); var sec = await kv.GetSecretAsync(WebConfigurationManager.AppSettings["SecretUri"]); //I put a variable in a Utils class to hold the secret for general application use. Utils.EncryptSecret = sec.Value;

    You can visit the below link for more information:

    https://docs.microsoft.com/en-us/azure/key-vault/key-vault-use-from-web-application

    Regards,

    Pratik

    Sunday, January 13, 2019 6:17 AM
  • Thanks Pratik,

    But my intention is not t maintain any where as in keyvault r configuration as the appid id present in token cliams if i able to get directly using received appid it will be helpful.

    I give you a scenario:

    I have API which is already in production quite some time. No updates from past couple of years and no developer actively working on the project. We are not sure who ever is consuming the API, some prod azure admin will provide access to others who want to consume. As the API has some perf issues Now there was a requirement that need to know metrics based on who is calling and etc etc so its hard to get the data. As i get the Appid in the claims if i able to find the app name it will be really easy handle.

    As API already in production needs very minimal code changes.

    Sunday, January 13, 2019 12:30 PM
  • So, basically, you want to trace the source details of the API call?
    Sunday, January 13, 2019 5:05 PM
  • Hi Bhasker,

    You can use Azure Sign-In logs to get the information about application usage where you are can narrow down the sign in data using the Application filter which you care about. You can also download the sign-in data and the Azure portal also provides you with option to generate script to download the data.

    Please refer to Sign-in activity reports in the Azure Active Directory portal

    Thanks
    Saurabh
    Monday, January 14, 2019 11:16 PM
  • Did you get a chance to look into earlier response if that helped ?
    Thursday, January 17, 2019 7:09 PM
  • I have an API that has been running for a long time. Over the past few years there have been no updates, and not one developer is actively working on the project. We are not sure whoever consumes the API, some Prad eagyur will give access to those people who want to consume. Since there are some correct problems in the API, it now became necessary to call metrics in order to know who was calling, etc. It is difficult to get data. As soon as I get the AppID in the claims, if I manage to find the name of the application, then it will be really easy to handle.



    Thursday, January 17, 2019 7:23 PM
  • Hi Saurabh,

    That doesnt solve the issue. I need to get the App name at runtime. I cannot download the logs when ever a call made to my api and get the details.

    My requirement is simple as i am able to get the Application Id from the token now i want the App name Associated with that Application id.

    Info:

    1. Token will be App generated token

    2. No key value pair in any configs or azure key vault

    AAD Appname from code

    • Edited by bhasker412 Friday, January 18, 2019 12:01 PM
    Friday, January 18, 2019 11:59 AM
  • You can try adding "app_displayname" customized claim to the token to get the application name.  Please refer to documentation to customize claims emitted in tokens for a specific app in a tenant, however, this feature is currently in Preview.

    Tuesday, February 5, 2019 11:04 PM
  • Hi Bhasker,

    Just checking in to see if you found the above reply helpful. If so, please remember to "Mark as answer" so that others in the community facing similar problems can more easily find a solution.

    Wednesday, February 6, 2019 11:37 PM
    Owner
  • Thanks Saurabh,

    This solves that problem. I am looking for the same.

    Thursday, February 7, 2019 3:04 PM
  • Great to hear that it worked for you. 
    Thursday, February 7, 2019 3:32 PM