Skip to content

SharePoint REST API Proxy for Node.js and Express local serve

License

Notifications You must be signed in to change notification settings

opencasa/sp-rest-proxy

 
 

Repository files navigation

sp-rest-proxy - SharePoint REST API Proxy for Node.js and Express local serve

Concept for REST API proxy to SharePoint tenant as if it were a local API.

NPM

npm version Downloads

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.

Supported SharePoint versions:

  • SharePoint Online
  • SharePoint 2013
  • SharePoint 2016

How to use as a module:

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.

How to develop:

Install:

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:

REST Client Example

Authentication settings

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 domain
    • password
    • 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.

Some additional info

sp-rest-proxy works with PnP JS Core (not POST request, as there is an endpoint transformation during POST request in PnP JS Core):

PnP JS Core + sp-rest-proxy

About

SharePoint REST API Proxy for Node.js and Express local serve

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 60.0%
  • HTML 36.5%
  • CSS 3.5%