【发布时间】:2023-04-10 12:25:02
【问题描述】:
我正在尝试通过 SharePoint REST API 将 Office 365 组织 SharePoint 网站用作 Rails 应用程序中生成的 docx 文件的存储点。我已经通过https://<domain>.sharepoint.com/_layouts/15/appregnex.aspx 注册了该应用程序并获得了client_id 和client_secret。使用https://<domain>.sharepoint.com/_layouts/15/appinv.aspx,我为应用授予了以下权限:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>
使用 oauth2 gem,到目前为止,我已经设法使用 client_credentials 获取访问令牌:
client = OAuth2::Client.new(<client_id>, <client_secret>, site: "https://<domain>.sharepoint.com", token_url: "https://login.windows.net/<tenant_id>/oauth2/token")
token = client.get_token(grant_type: "client_credentials", client_id: client.id, client_secret: client.secret, resource: "https://<domain>.sharepoint.com")
client_credentials 策略似乎有效,因为收到了令牌。但是,尝试使用它会导致失败。
token.get("/_api/web/title") 返回OAuth2::Error: { "error_description" : "The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs." }
RestClient.get("https://<domain>.sharepoint.com/_api/web/title", { "Authorization" => token.token }) 返回RestClient::Unauthorized: 401 Unauthorized
我对此几乎束手无策,我这个接近告诉我的老板,如果它可以以某种方式完成,我只是没有足够的知识去做它。
【问题讨论】:
标签: rest ruby-on-rails-4 ms-office sharepoint-2013 office365