我正在尝试使用 OAuth2 和 REST API 连接到 Sharepoint Online (Sharepoint 365?) 内容。我需要从 Python 执行此操作,因为它是对现有应用程序的补充。我已经设法使用 OAuth2 和 REST 将应用程序连接到 Google Drive,所以我想我了解使用 OAuth2 的基础知识。
我尝试了多种位置组合来配置 client_id 和 client_secret 并进行身份验证和接收访问和刷新 token 。
到目前为止,我已经能够接收刷新 token 并使用它来获取访问 token ;但是,我无法使用访问 token 访问 Sharepoint 365 站点上的内容。
为了配置 client_id 和 client_secret,我使用 Azure 管理门户将我的 Sharepoint 站点与 AAD 相关联。然后我将一个应用程序添加到 Sharepoint AD 条目,其中包含 client_id 和 client_secret。在 Sharepoint 中,我使用 appregnew.aspx 注册 client_id 并验证应用程序出现在 appprincipals.aspx 中。
我使用以下方法调用身份验证服务:
.../login.windows.net/common/oauth2/authorize?api-version=1.0&response_type=code&client_id=&redirect_uri=&resource=Microsoft.Sharepoint
并且能够进行身份验证、接收代码、回电
.../login.windows.net/common/oauth2/token 使用代码并接收访问和刷新 token 。
我从一个单独的进程调用序列化了这些 token
.../login.windows.net/common/oauth2/token 带有 refresh_token、client_id、client_secret 和 grant_type=refresh_token,并接收新的访问 token 。
最后我调用 Sharepoint 服务端点
-my.sharepoint.com/personal//_api/web/files'
使用新的访问 token ,但它无法告诉我资源 Microsoft.Sharepoint 无效(无效的受众 Uri 'Microsoft.SharePoint')
我一直在旋转我的轮子,尝试配置 client_id 的位置的各种排列,这是我得到的。由于所有文档和示例似乎都依赖于使用诸如 TokenHelper 之类的 C# 库,因此我觉得我缺少一些关键但简单的东西,并且找不到所需的信息。
有没有人使用 Python、Ruby、Java 等连接到 Sharepoint Online?如果是这样的话:
非常感谢!
最佳答案
我已使用 PHP 成功连接到 SharePoint Online。在我看来,您正在结合两种不同的方法来做到这一点。
这是我所做的:
appregnew.aspx 和 appprincipals.aspx 页面用于 SharePoint 应用程序,但它看起来不像您正在构建的应用程序。
关于sharepoint - 用于 SharePoint 365 REST 的 Oauth2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25110408/