Click here to Skip to main content
15,313,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
      I want to get microsoft azure active directory roles in dot net core using TenantId and RedirectUri. I am having ClientId, TenantId, RedirectUri, Endpoints. So now how to get microsoft azure active directory roles based on these keys in dotnet core.


What I have tried:

public async Task<List<KeyValueModel>> GetAzureRoleAsync(string clientId, string tenantId, string redirectUri, string endpoints)
        {
            //string tenantID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid Jump ").Value;
            Uri servicePointUri = new Uri("http://localhost:44332");
            Uri serviceRoot = new Uri(servicePointUri, tenantId);

            var model = new List<KeyValueModel>();

            ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot, async () => await UserHelper.GetTokenForApplication());
            IPagedCollection<IApplication> retrievedApps = activeDirectoryClient.Applications.Where(w => w.AppId.Equals(ConfigHelper.ClientId)).ExecuteAsync().Result;
            if (retrievedApps != null)
            {
                Application adApp = (Application)retrievedApps.CurrentPage.FirstOrDefault();
                if (adApp != null)
                {
                    adApp.AppRoles.ToList().ForEach(e =>
                    {                        
                        model.Add(new KeyValueModel { Key = e.Id.ToString(), Value = e.DisplayName });
                    });
                }
            }
            return model;
        }









public class KeyValueModel
   {
       public string Key { get; set; }
       public string Value { get; set; }
   }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900