我正在try 构建一个.NET8控制台应用程序,它将使用仅限应用程序的权限来执行一些Microsoft Graph调用.该应用程序使用证书来获取令牌,并且应该在没有任何用户提示的情况下对自己进行身份验证.
下面的代码之所以起作用,是因为我能够将WithAppOnly选项设置为仅与应用程序权限一起使用:
var devices = await graphServiceClient.DeviceManagement.ManagedDevices.GetAsync(r => r.Options.WithAppOnly());
但是,如果我try 遍历所有页面,似乎PageIterator忽略了WithAppOnly选项,因此我得到以下错误:
IDW10502:由于质询的原因引发了MsalUiRequiredException 用户.
下面是我用来迭代的代码:
var devicelist = new List<DeviceModel>();
var pageIterator = PageIterator<ManagedDevice, ManagedDeviceCollectionResponse>.CreatePageIterator(graphServiceClient, devices, (device) =>
{
devicelist.Add(DeviceModelMapper.MapFromManagedDevice(device));
return true;
});
await pageIterator.IterateAsync();
如何将with AppOnly请求选项添加到迭代器?或者我可以在我的图形客户端中添加WithAppOnly选项作为默认选项吗?
在最坏的情况下,我如何在没有迭代器的情况下遍历页面?
谢啦!