我目前正在try 根据应用ID列表过滤Azure应用程序.我已经做好了必要的设置,图形服务客户端具有"Application.ReadWrit.OwnedBy"权限,并且同一客户端应用程序作为所有者添加到我要检索的应用程序中.我有下面的代码片段,它基于单个appId进行过滤,但我想修改它以基于整个appId列表进行过滤.

我当前用于过滤单个appId详细信息的代码段

var appIds = ["id1","id2","id3"]
var applications = await this.graphServiceClient.ApplicationsWithAppId(appIds[0]).GetAsync((requestConfiguration) => requestConfiguration.QueryParameters.Select = ["id", "appId", "displayName", "requiredResourceAccess"]);

我想根据整个appIds数组进行过滤

推荐答案

我注册了一个应用程序,添加了"Application.ReadWrite.OwnedBy"Application类型的权限,如下所示:

enter image description here

现在,我将其作为Owner添加到我要检索的应用程序中:

enter image description here

对于基于整个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:

enter image description here

Csharp相关问答推荐

IComponition.获取IReadOnlyCollection的返回默认属性值

如何在Visual Studio中为C# spread操作符设置格式规则?

无法从具有一对多关系的C#类中使用Swagger创建记录

SignalR客户端不会打印队列位置'

为什么我的ASP.NET核心MVC应用程序要为HTML元素添加一些标识符?

需要澄清C#的Clean Architecture解决方案模板的AuditableEntityInterceptor类

使用命令初始化可绑定属性

Int和uint相乘得到LONG?

如何使用自定义负载均衡器管理Ocelot负载均衡器中的多线程和批读取

单元测试:模拟返回空

使用带有参数和曲面的注入失败(&Q;)

为什么Azure函数(独立工作进程)索引失败?使用Azure App配置的CosmosDbTrigger绑定失败,未解析为值

使用ASP.NET MVC for Lemon Squeezy X-Signature创建散列

如何在一次数据库调用中为ASP.NET核心身份用户加载角色

Cmd中的&ping.end()";有时会失败,而";ping";总是有效

SqlException:无法打开数据库.升级到Dotnet 8后-数据库兼容性版本-非EFCore兼容性级别

单位中快照的倾斜方向

.NET6最小API:操作.MapGet之后的响应

在c#中,使用Okta和Blazor时,LocalReDirect()陷入循环,出现错误&请求太多.

ASP.NET核心中的验证错误-该字段为必填字段