koltyakov / sp-rest-proxy

🌐 SharePoint API Proxy for local development
MIT License
172 stars 43 forks source link

thanks. SP2010 #12

Closed johnnliu closed 7 years ago

johnnliu commented 7 years ago

I've had successful results connecting this to SP2010 on-premises.

_api needs to change to _vti_bin/listdata.svc so there were some hacks. But it works 👍

need to think a bit more about how to support this properly, do you want to add a flag to config to specify which SharePoint the user is running?

koltyakov commented 7 years ago

Hi John,

Interesting. What about authentication? I have never tried node-sp-auth with 2010. I don't even have SP 2010 environment nowadays, to test it right away.

Actually, /_api shouldn't be changed to /_vti_bin. It's possible to have multiple routers, just like in the case of SOAP implementation, when app.use('*/_vti_bin', _self.routers.apiSoapRouter); routes to a specific request builder depending on URI pattern.

need to think a bit more about how to support this properly, do you want to add a flag to config to specify which SharePoint the user is running?

Yep. We got to think more. Base implementation can stay as it is, as there was no /_api endpoint alias in SP 2010, but /_vti_bin part should be thought in some way to deal with ASMX's and SVC's simultaneously. Also, I'm not sure about authentication.

-- Andrew

johnnliu commented 7 years ago

Stabbed at this a bit more today - I was able to use apiSoapRouter to proxy POST requests to custom .svc as well. For this on-premises customer I had many REST Soap services deployed which I'm proxy'ing. Had to tell the apiSoapRouter (which auth with NTLM) to not parse body as XML and keep it as JSON instead.

There is still the issue of scrubbing the page for a FormDigest for listdata.svc. As there is no _api/contextinfo. I think this is a task that should be done by in node-sp-auth though.

Ultimately this might just be too crazy.

I've hacked the index.js to pieces I feel bad.

koltyakov commented 7 years ago

Hey @johnnliu,

Last months sp-rest-proxy received a lot of new features. I had no chance to document them all. In a few words, almost any request can be forwarded via proxy, including JSOM, batch API (for SPO and 2016) and static content. SharePoint pages can be even opened in proxy's hostname. Also proxy got a new mode for socket server and client which allows target to SharePoint server in NAT network without VPN or external IP.

Also, I got a chance to test node-sp-auth's NTLM authentication with SP 2010, I was surprised, but it works like a charm.

I've checked some request to /_vti_bin/listdata.svc: getting list of lists, getting list's items, creating an item with:

var listName = 'Test';
$.ajax({
    url: "http://localhost:8080/sites/help/_vti_bin/listdata.svc/" + listName,
    type: "POST",
    processData: false,
    contentType: "application/json;odata=verbose",
    data: JSON.stringify({ "Title": "test" }),
    headers: {
        "Accept": "application/json;odata=verbose"
    },
    success: function(data) {
        console.log(data.d);
    },
    error: function(err) {
        console.log(err);
    }
});

It works with the combination of sp-rest-proxy and SharePoint 2010 now.

Theoretically, even multipart batch request should work (POST http://contoso/sites/sharepointlist/_vti_bin/listdata.svc/$batch HTTP/1.1).

I'm not going to add full support for 2010 and integration tests, at least for now, but I have a feeling that most scenarios (SOAP, legacy REST, JSOM, static content) with SP 2010 should work as well.

It would be great if you could take a look and test your scenarios with SharePoint 2010 and the latest version of sp-rest-proxy.

Thanks!

Closing this issue, but feel free to reopen if anything won't work.

johnnliu commented 7 years ago

I only just saw this. will try hopefully soon.