Sharepoint Online 和 Azure Tokens

huangapple go评论55阅读模式
英文:

Sharepoint Online & Azure Tokens

问题

我正在尝试为一个使用CSOM查询Sharepoint列表和pnp.core获取客户端上下文的C#应用程序进行授权登录。

我已经注册了一个应用程序,其中包含一个客户端密钥。该注册包括以下权限:Allsites.read 和 Allsites.write。

   string siteUrl = "我的站点";
   string clientId = "我的应用程序客户端ID";
   string tenantId = "我的租户ID";
   string clientSecret = "*******";

    using var clientContext = new AuthenticationManager()
                             .GetACSAppOnlyContext(siteUrl, clientId, clientSecret); 
      clientContext.Load(clientContext.Web);
      clientContext.ExecuteQuery();
      Console.WriteLine(clientContext.Web.Title);

上述代码似乎可以正确读取密钥(如果我更改密钥,它会失败并显示密钥无效错误),但当我尝试访问 web 的 title 属性时,我收到了 403 禁止访问的错误。

我不太确定我在哪里出错了,因此非常感谢任何见解。

英文:

I'm trying to authorise login for a c# app that uses CSOM to query Sharepoint lists and pnp.core to get the client context.

I have an app registration with a client secret. The registration has the permissions Allsites.read & Allsites.write

   string siteUrl ="mysite";
   string clientId = "my app client id";
   string tenantId = "my tenant id";
   string clientSecret = "*******";

    using var clientContext = new AuthenticationManager()
                             .GetACSAppOnlyContext(siteUrl, clientId, clientSecret); 
      clientContext.Load(clientContext.Web);
      clientContext.ExecuteQuery();
      Console.WriteLine(clientContext.Web.Title);

The above code seems to read the key OK (if I change the secret it fails with a key invalid error) but when I try and access the title property of the web I get a 403 Forbidden error.

I'm not sure where I am going wrong here, so any insights would be much appreciated.

答案1

得分: 1

AllSites.ReadAllSites.Write 权限与已登录用户关联,但您作为守护程序连接而没有已登录用户。

在这种情况下,您需要在Azure AD中添加应用程序权限 Sites.ReadWrite.All

Sharepoint Online 和 Azure Tokens

英文:

AllSites.Read and AllSites.Write permissions are tied with the signed-in user but you connect as a daemon without a signed-in user.

In that case you need to add application permissions Sites.ReadWrite.All in Azure AD.

Sharepoint Online 和 Azure Tokens

huangapple
  • 本文由 发表于 2023年6月15日 19:12:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定