0

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://learn.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.learn.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.

MS API DOC Multi tenant Screenshot

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. How to get all Azure AD account list using token generated by user_impersonation scope on /common endpoint (same question. but there is no answer for that)

Airn5475
  • 2,452
  • 29
  • 51
dglumesh
  • 101
  • 1
  • 4
  • 15
  • As far as I knew, one time we just can get a token from one tenant. So we can use list tenants api to get all tenants and refresh token with every tenant. – Jim Xu Aug 19 '20 at 01:06
  • can you please explain how to refresh token with every tenant? – dglumesh Aug 20 '20 at 02:42
  • Please refer to the sample: https://github.com/Azure-Samples/billing-dotnet-webapp-multitenant/ – Jim Xu Aug 20 '20 at 03:18
  • can you please mention the file name? i'm bit struggling to find the location – dglumesh Aug 20 '20 at 06:17
  • You can refer to https://github.com/Azure-Samples/billing-dotnet-webapp-multitenant/blob/master/WebApp-Billing-MultiTenant/ISVDemoUsage/AzureResourceManagerUtil.cs. – Jim Xu Aug 20 '20 at 06:20

0 Answers0