c# - 如何使用客户端 ID 和客户端密码在 C# .NET Framework 中使用 SharePoint Rest API?
问题描述
有什么方法可以使用客户端 ID 和客户端密钥对带有 SharePoint REST API(如 Graph API)的应用程序进行身份验证?我想在我的控制台应用程序中使用 SharePoint REST API。
解决方案
这对我有用:
在 Azure Active Directory 中,我为 SharePoint API 配置了权限。
在我的代码中,我以这种方式定义了范围:
var scopes = new [] {"https://<tenantName>.sharepoint.com/allsites.manage"};
var clientApp = ConfidentialClientApplicationBuilder.Create($"{clientId}")
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.WithClientSecret($"{clientSecret}").Build();
// acquire a token for the app
AuthenticationResult result = null;
try
{
result = await clientApp.AcquireTokenForClient(scopes)
.ExecuteAsync();
}
catch (MsalUiRequiredException ex)
{
...
}
catch (MsalServiceException ex)
{
...
}
推荐阅读
- docker - 如何在 Gitlab 上要求 Docker 认证的图像?
- c# - 将大型 .txt 文件与值数组进行比较
- r - 依赖于两个文件的编程函数
- java - 无法使用 Java 进程的 gdb 核心反汇编 $PC
- istio - 设置 istio 1.2.1 时,许多指标都是空的 - 我做错了什么?
- android - Android Studio 启用离线模式不起作用
- autodesk - 设计自动化 API 无法打开 zip 文件
- python - 排序-TypeError:'int'和'str'的实例之间不支持'<',Python
- excel - 如何从带有标题的记录集中复制?
- arrays - PowerShell 3.0 -iin 运算符支持通配符吗?如何以类似的方式使用 -ilike?