Click here to Skip to main content
14,576,731 members
Rate this:
Please Sign up or sign in to vote.
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100