Welcome
Learn about building Web apps with ASP.NET Core.
Skill Set Matrix | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code Sample C# Azure Functional App | ||
|
[Function("Groups")]
public async Task
{
EntraGroups? entraGroups = null;
_logger.LogInformation("C# HTTP trigger function processed a request.");
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var request = JsonConvert.DeserializeObject
var tenantUId = request?.TenantUId.ToString("D");
var clientId = Environment.GetEnvironmentVariable("ClientId");
var clientSecret = Environment.GetEnvironmentVariable("ClientSecret");
try
{
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(
request?.TenantUId.ToString("D"), clientId, clientSecret, options);
var graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
var groupList = new List
var groupsResponse = await graphServiceClient
.Groups
.GetAsync(requestConfiguration => {
requestConfiguration.QueryParameters.Filter = $"groupTypes/any(c: c eq 'Unified')";
requestConfiguration.QueryParameters.Select = new string[] { "id", "displayName", "description", "Mail", "Members", "createdDateTime" }; requestConfiguration.QueryParameters.Top = 60;
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
var grpIterator = PageIterator
.CreatePageIterator(graphServiceClient, groupsResponse, (group) => { groupList.Add(group); return true; });
await grpIterator.IterateAsync();
entraGroups = new EntraGroups();
foreach (var group in groupList)
{
var entraGroup = new EntraGroup
{
Id = new Guid(group.Id),
Name = group.DisplayName,
Description = group.Description,
Email = group.Mail
};
entraGroups.Items.Add(entraGroup);
}
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
return new ObjectResult(new { statusCode = 500, Message = ex.Message });
}
return new OkObjectResult(entraGroups);
}