【问题标题】:Get SharePoint Office 365 data using Client Id使用客户端 ID 获取 SharePoint Office 365 数据
【发布时间】:2019-05-12 20:52:24
【问题描述】:

我正在使用以下代码访问 SharePoint 在线列表数据,但出现以下错误。

The remote server returned an error: (403) Forbidden.

Web 表单应用程序在 Azure 中运行并使用 Azure 身份验证。我想使用相同的凭据进行身份验证

    string siteUrl = "[url]";
    string aadAppId = "[appid]";
    string clientSecret = "[redacted]";
    OfficeDevPnP.Core.AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager();
    ClientContext context = authManager.GetAzureADNativeApplicationAuthenticatedContext(siteUrl, aadAppId, appurl, null, AzureEnvironment.Production);
        if (context != null)
            {
             Web web = context.Web;
             context.Load(web);
             context.ExecuteQuery();
            }

我不想使用用户凭据访问 SharePoint。

我已在 Web 应用上启用 AAD Azure 身份验证。 Web 应用使用 Azure 凭据进行身份验证。

在 CORS 设置中,我还将域 URL 设置为 "https://domainname.sharepoint.com";

在 AAD 应用程序的管理权限部分,我已授予应用程序读取和写入共享点列表和 Web 数据的权限。

【问题讨论】:

  • 如果您发布的秘密值是真实的,请务必立即将其从您的应用注册中删除。

标签: azure-active-directory sharepoint-online spfx


【解决方案1】:

您的示例正在尝试将令牌作为本机客户端应用程序检索,该应用程序无法保密且无法自行进行身份验证。 (这就是为什么你会注意到你从不使用clientSecret。)

如果您想使用 OfficePnP,您可以尝试 AuthenticationManager.GetAzureADAppOnlyAuthenticatedContext 方法之一在纯应用上下文中进行身份验证。请注意,它们都需要证书来进行身份验证,而不是秘密。

【讨论】:

  • 感谢 Philippe 的回复,但那需要我安装证书。有没有什么方法可以在不安装证书的情况下实现它。
  • 您能否分享一些有关您无法使用证书的用例的详细信息?
  • 您好 Philiippe,我无法安装证书,因为我没有权限并且管理员不想在 Azure 中安装证书
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
  • 1970-01-01
  • 2023-02-08
  • 1970-01-01
  • 2015-08-04
相关资源
最近更新 更多