How to get azure account tenant wise token from ASP .Net Web App RRS feed

  • Question

  • I have app with ASP .Net MVC. I need to get tenant wise subscription list from Azure service management api. This can done by -> https://docs.microsoft.com/en-us/rest/api/resources/subscriptions/list#code-try-0

    I can get token with 'user_impersonation' scope from my web app. To that token I can only get default account tenant subscription list only. But I want subscription list from another tenant that I have access from my account.
    Microsoft get those tenant wise token array from https://token.docs.microsoft.com/accesstokens. Its receive array of tokens for each tenant that I have access for subscriptions. Those tokens works totally fine for getting tenant wise subscription list.

    Please refer the code that I use to get tokens.

        string token = await GeAccessToken(new string[] { "https://management.core.windows.net//user_impersonation" });
        private async Task<string> GetAccessToken(string[] scopes)
        IConfidentialClientApplication cc = MsalAppBuilder.BuildConfidentialClientApplication();
        IAccount userAccount = await cc.GetAccountAsync(ClaimsPrincipal.Current.GetMsalAccountId());
        Microsoft.Identity.Client.AuthenticationResult result = await cc.AcquireTokenSilent(scopes, userAccount).ExecuteAsync();
        return result.AccessToken;

    I need to know how to get that token array from my application. https://stackoverflow.com/questions/59751313/how-to-get-all-azure-ad-account-list-using-token-generated-by-user-impersonation  (same question. but there is no answer for that)

    • Moved by CoolDadTx Thursday, August 13, 2020 1:32 PM ASP.NET related
    Thursday, August 13, 2020 10:34 AM

All replies

  • Hello,

    Please use the following forum https://forums.asp.net/1247.aspx/1?Azure+and+ASP+NET

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, August 13, 2020 11:03 AM