微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用客户端 ID 和客户端密钥在 C# .NET Framework 中使用 SharePoint Rest API?

如何解决如何使用客户端 ID 和客户端密钥在 C# .NET Framework 中使用 SharePoint Rest API?

有什么方法可以使用客户端 ID 和客户端密钥通过 SharePoint Rest API(例如 Graph API)对应用程序进行身份验证?我想在我的控制台应用程序中使用 SharePoint rest API。

解决方法

这对我有用:

在 Azure Active Directory 中,我为 SharePoint API 配置了权限。 enter image description here

在我的代码中,我以这种方式定义了范围:

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)
{
...
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。