太简单了:
几天来,我一直在为这件事而挣扎,但到目前为止还没有这样的运气。
签出选项1-图API
即使它是OneDrive API,它也应该与SharePoint doc.libraries一起运行- RESt APIs部分:“ REST在OneDrive、OneDrive for Business、SharePoint文档库和Office之间共享,以允许.”
结果是什么呢?看看这里: when checkin/chekout file
好消息是,OAuth工作起来很有魅力--我从https://apps.dev.microsoft.com/获得了客户端ID,即身份验证端点:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize https://login.microsoftonline.com/common/oauth2/v2.0/token
签出选项2- Sharepoint外接程序
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest
url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/CheckOut(),
method: POST
headers:
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value这个很好,但在这种情况下,OAuth是问题所在.
然而,在此过程中,涉及到Microsoft访问控制服务(ACS),根据该链接https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-acs-migration,该即将关闭。
解决方案似乎是切换到Azure应用程序(https://portal.azure.com -> Azure Active Directory ->应用程序注册)。无论如何,使用这些设置的访问令牌与Sharepoint API所需的访问令牌不兼容,例如:
https://mindjet2.sharepoint.com/_api/contextinfo抛出异常'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException'
我对图形api做错了什么?使用OAuth验证Sharepoint的正确方法是什么?
发布于 2018-03-13 09:37:27
在SharePoint外接程序中,我们可以使用跨域库来实现它.
检查下面的代码:
'use strict';
var hostweburl;
var appweburl;
// This code runs when the DOM is ready and creates a context object which is
// needed to use the SharePoint object model
$(document).ready(function () {
//Get the URI decoded URLs.
hostweburl =
decodeURIComponent(
getQueryStringParameter("SPHostUrl"));
appweburl =
decodeURIComponent(
getQueryStringParameter("SPAppWebUrl"));
// Resources are in URLs in the form:
// web_url/_layouts/15/resource
var scriptbase = hostweburl + "/_layouts/15/";
// Load the js file and continue to load the page with information about the list top level folders.
// SP.RequestExecutor.js to make cross-domain requests
// Load the js files and continue to the successHandler
$.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
});
// Function to prepare and issue the request to get
// SharePoint data
function execCrossDomainRequest() {
// executor: The RequestExecutor object
// Initialize the RequestExecutor with the app web URL.
var executor = new SP.RequestExecutor(appweburl);
var metatdata = "{ '__metadata': { 'type': 'SP.Data.TestListListItem' }, 'Title': 'changelistitemtitle'}";
// Issue the call against the app web.
// To get the title using REST we can hit the endpoint:
// appweburl/_api/web/lists/getbytitle('listname')/items
// The response formats the data in the JSON format.
// The functions successHandler and errorHandler attend the
// sucess and error events respectively.
executor.executeAsync({
url:appweburl + "/_api/SP.AppContextSite(@target)/web/GetFileByServerRelativeUrl('/Shared Documents/a.txt')/CheckOut()?@target='" +
hostweburl + "'",
method: "POST",
body: metatdata ,
headers: { "Accept": "application/json; odata=verbose", "content-type": "application/json; odata=verbose", "content-length": metatdata.length, "X-HTTP-Method": "MERGE", "IF-MATCH": "*" },
success: function (data) {
alert("success: " + JSON.stringify(data));
},
error: function (err) {
alert("error: " + JSON.stringify(err));
}
});
}
// This function prepares, loads, and then executes a SharePoint query to get
// the current users information
//Utilities
// Retrieve a query string value.
// For production purposes you may want to use
// a library to handle the query string.
function getQueryStringParameter(paramToRetrieve) {
var params =document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
var singleParam = params[i].split("=");
if (singleParam[0] == paramToRetrieve)
return singleParam[1];
}
} https://stackoverflow.com/questions/49250476
复制相似问题