小编gtr*_*edi的帖子

在 C# 中使用 authProvider 和 MS SDK 进行图形调用

我正在尝试创建一个 C# 控制台应用程序来连接到图形 API 并从租户中获取来自 AzureAD 的用户列表。我已经注册了应用程序,管理员给了我以下内容

  • 租户名称和租户 ID
  • 客户端 ID(有时也称为应用 ID)
  • 客户机密

使用 sdk,我需要使用的 C# 代码如下所示(https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=cs):

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var users = await graphClient.Users
    .Request()
    .GetAsync();
Run Code Online (Sandbox Code Playgroud)

但是,控制台应用程序将作为批处理运行,因此根本没有用户交互。因此,为了提供 authProvider,我在 MS 文档站点上关注了这篇文章:https ://docs.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS

而且我认为出于我的目的,我需要使用“客户端凭据 OAuth 流程”。该 URL 上显示的代码。但这里也是。

IConfidentialClientApplication clientApplication = ClientCredentialProvider.CreateClientApplication(clientId, clientCredential);
ClientCredentialProvider authProvider = new ClientCredentialProvider(clientApplication);
Run Code Online (Sandbox Code Playgroud)

问题是 Visual Studio 无法识别 ClientCredentialProvider 类。我不确定要导入哪个程序集。我在顶部使用以下用途。

using Microsoft.Identity.Client;
using Microsoft.IdentityModel.Clients;
using Microsoft.IdentityModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Run Code Online (Sandbox Code Playgroud)

我对 GitHub 存储库不是很有经验,我使用的是 Visual …

c# azure-active-directory microsoft-graph-api

15
推荐指数
1
解决办法
2万
查看次数

Microsoft Graph 仅返回前 100 个用户

我有以下代码,它根据过滤器返回所有用户。问题是它只返回 100 个用户,但我知道还有更多。

private List<User> GetUsersFromGraph()
{
    if (_graphAPIConnectionDetails == null) ReadParametersFromXML();
    if (graphServiceClient == null) graphServiceClient = CreateGraphServiceClient();

    var users = graphServiceClient
        .Users
        .Request()
        .Filter(_graphAPIConnectionDetails.UserFilter)
        .Select(_graphAPIConnectionDetails.UserAttributes)
        .GetAsync()
        .Result
        .ToList<User>();

    return users;
}
Run Code Online (Sandbox Code Playgroud)

该方法仅返回 100 个用户对象。我的 Azure 门户管理员报告说应该接近 60,000。

c# microsoft-graph-sdks microsoft-graph-api

3
推荐指数
1
解决办法
3104
查看次数

C# 创建zip,添加文件但无法打开

我不是 C# 开发人员,所以我的知识有限。但是,我正在尝试用 C# 编写一个程序,导出特定日期的 Windows 安全日志并将其导出为 evtx 文件。

但接下来我要做的就是将此 evtx 文件添加到 zip 文件中。下面的代码创建 zip 文件(我可以看到它)并将 evtx 文件添加到 zip (我认为是因为在 Windows 中探索大小从 0kb 更改为更多)。

#region "COMPRESS THE EVTX FILE INTO A ZIP FILE: "
// First create a new ZIP archive in the "Achives" folder.
string zipFileName = "Zip-" + getDateTimeStamp(1) + ".zip";
string zipFilePath = System.IO.Path.Combine(zipEvtxDirectoryPath, zipFileName);
ZipArchive zipFile = ZipFile.Open(zipFilePath, ZipArchiveMode.Create);

// Add the evtx file created in program directory to this zip archive.
Console.WriteLine(evtxFilePath);
Console.WriteLine(evtxFileName);
zipFile.CreateEntryFromFile(evtxFilePath, evtxFileName); …
Run Code Online (Sandbox Code Playgroud)

c# zip

1
推荐指数
1
解决办法
4056
查看次数