Use sharepoint cross-domain javascript library to consume REST API from localhost

自闭症网瘾萝莉.ら 提交于 2019-12-23 04:26:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!