问题
I try to consume the sharepoint rest API from an application deployed in localhost. The sharepoint site is hosted in Sharepoint 2013 online.
For that purpose I use the javascrpt cross domain library. I get an example here https://github.com/OfficeDev/SharePoint-Add-in-REST-OData-CrossDomain.
My application is a full static website and I don't have VS, so I tried to figure out the Add In authorization. I go to the _layouts/15/appinv.aspx
page of my site to give the authorization of third party application:
- app domain: localhost:8080
- redirect url: http://localhost:8080 (pointless?)
- permission request XML:
<AppPrincipal><RemoteWebApplication ClientId="*" /></AppPrincipal>
When I go to my application, I'm authenticated with my account: the cookie is populated with the token in FedAuth
and rtFa
I'm supposing that it should be enough to now consume the API:
var executor = new SP.RequestExecutor(addinweburl);
executor.executeAsync(
{
url:
addinweburl + "/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents')"
,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function(e) {
alert('success');
},
error: function(e, c, d) {
alert('fail');
}
}
);
The error handler is called and the 1007 error code is sent. This is quite weird since this code is used when size is too important.
Any help is appreciated.
回答1:
The library can't be used if the application is not deployed on the same sharepoint site domain...
I fallback to OAuth protocol in order to authenticate my client. The following documentation was key to understand how to obtain an access token: https://github.com/wearearchitect/sharepoint-oauth-app-client/blob/master/docs/Credentials.md
来源:https://stackoverflow.com/questions/36035221/use-sharepoint-cross-domain-javascript-library-to-consume-rest-api-from-localhos