Как получить роли Microsoft azure active directory в dot net core
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.
Что я уже пробовал:
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; } }