我注册了一个应用程序,添加了"Application.ReadWrite.OwnedBy"个Application类型的权限,如下所示:
现在,我将其作为Owner添加到我要检索的应用程序中:
对于基于整个appIds
数组的filter个应用程序,您可以使用以下示例代码:
using Azure.Identity;
using Microsoft.Graph;
class Program
{
static async Task Main(string[] args)
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "tenantId";
var clientId = "appId";
var clientSecret = "secret";
var appIds = new[] { "appId1", "appId2", "appId3" };
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
};
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
try
{
var filterExpression = string.Join(" or ", appIds.Select(id => $"appId eq '{id}'"));
var applications = await graphClient.Applications
.GetAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Filter = filterExpression;
requestConfiguration.QueryParameters.Select = new string[] { "appId", "displayName" };
});
foreach (var application in applications.Value)
{
Console.WriteLine($"App Name: {application.DisplayName}");
Console.WriteLine($"App ID: {application.AppId}");
Console.WriteLine();
}
}
catch (ServiceException serviceException)
{
Console.WriteLine(serviceException.Message);
}
}
}
Response: