首页 > 解决方案 > 使用 CSOM 和 grant_type=client_credentials 访问 sharepoint\office 365

问题描述

我已按照此示例中的说明进行操作: https ://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard 并且可以正常连接:-) 使用grant_type=密码,用户名和密码

但是我想使用客户端 ID 和客户端密码进行连接...... 我已经在 AzureAD 中设置了这些

我添加了权限:

我已经暴露了api

这是我请求的正文

在代码中的这一点上,我实际上收到了令牌

但在这里它失败了 401

我想知道是否有人有这个工作的例子?

我也尝试过这个https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs 并且我可以让它工作,根据文档这已经在 11 月退休2018 年 7 月 7 日。

我不确定它使用什么身份验证方法或如何识别身份验证方法。

标签: sharepointazure-active-directoryoffice365csom

解决方案


If this registration is only used for SharePoint, you do not need to expose an API.

You don't need scope. You will need to pass in the 'client_id' and 'resource' like below and it will look something similar to this for getting a token to make a call to SharePoint:

client_id: [appRegistrationClientId]@[tenantid]
Resource: 00000003-0000-0ff1-ce00-000000000000/[tenant].sharepoint.com@[tenant-id]

enter image description here

This will help too: https://anexinet.com/blog/getting-an-access-token-for-sharepoint-online/


推荐阅读