Concept for REST API proxy to SharePoint tenant as if it were a local API.
Allows to perform API calls to local Express application with forwarding the queries to a remote SharePoint instance.
This concept was created to show how is could be easy to implements real world data communications for SharePoint Framework local serve mode during web parts debug without deployment to SharePoint tenant.
- SharePoint Online
- SharePoint 2013
- SharePoint 2016
1. Install NPM module in the project:
npm install --save-dev sp-rest-proxy
2. Create server.js with the following code:
var RestProxy = require("sp-rest-proxy");
var settings = {
configPath: __dirname + "/config/_private.conf.json", // Location for SharePoint instance mapping and credentials
port: 8080, // Local server port
staticRoot: __dirname + "/static" // Root folder for static content
};
var restProxy = new RestProxy(settings);
restProxy.serve();
Configuration parameters cheatsheet
3. Add npm task for serve into package.json:
"scripts": {
"serve": "node ./server.js"
}
Check if the path to server.js is correct.
4. Run npm run serve
.
5. Provide SharePoint configuration parameters.
6. Test local API proxy in action.
1. Clone the project:
git clone https://github.com/koltyakov/sp-rest-proxy
2. CMD to the project folder.
3. Install dependencies:
npm run build
4. Run the server:
npm run serve
Prompt credentials for a SharePoint site.
5. Navigate to http://localhost:8080
6. Ajax REST calls as if you were in SharePoint site page context:
Since communication module (sp-request), which is used in sppull, had received additional SharePoint authentication methods, they are also supported in sp-rest-proxy.
- SharePoint On-Premise (Add-In permissions):
clientId
issuerId
realm
rsaPrivateKeyPath
shaThumbprint
- SharePoint On-Premise (NTLM handshake - more commonly used scenario):
username
- username without domainpassword
domain
/workstation
- SharePoint Online (Add-In permissions):
clientId
clientSecret
- SharePoint Online (SAML based with credentials - more commonly used scenario):
username
- user name for SP authentication [string, required]password
- password [string, required]
- ADFS user credantials:
username
password
relyingParty
adfsUrl
For more information please check node-sp-auth credential options and wiki pages.
Auth settings are stored inside ./config/_private.conf.js
.
sp-rest-proxy works with PnP JS Core (not POST request, as there is an endpoint transformation during POST request in PnP JS Core):