string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
string clientId = "";
string tenantId = "";
string secret = "";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
try
{
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, secret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var groups = graphClient.Users["f32f3633-dab2-4828-93d7-57f28b39e6f1"].MemberOf.Request().GetAsync().Result;
var result = new List<Guid>();
while (groups.Count > 0)
{
foreach (var group in groups)
{
result.Add(new Guid(group.Id));
}
if (groups.NextPageRequest != null)
{
groups = groups.NextPageRequest.GetAsync().Result;
}
else
{
break;
}
}
}
catch (Exception ex)
{
throw;
}
string clientId = "";
string tenantId = "";
string secret = "";
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
try
{
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, secret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var groups = graphClient.Users["f32f3633-dab2-4828-93d7-57f28b39e6f1"].MemberOf.Request().GetAsync().Result;
var result = new List<Guid>();
while (groups.Count > 0)
{
foreach (var group in groups)
{
result.Add(new Guid(group.Id));
}
if (groups.NextPageRequest != null)
{
groups = groups.NextPageRequest.GetAsync().Result;
}
else
{
break;
}
}
}
catch (Exception ex)
{
throw;
}
Comments
Post a Comment