• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unattended SharePoint http authentication with nodejs

node-sp-auth - nodejs to SharePoint unattended http authentication

NPM npm version

Need help on SharePoint with Node.JS? Join our gitter chat and ask question! Gitter chat


IMPORTANT: This module doesn't work in browser. The only supported environment is nodejs. If you have a need to use it in browser, probably you're looking for sp-rest-proxy - a nodejs proxy, which redirects calls to real SharePoint.


node-sp-auth allows you to perform SharePoint unattended (without user interaction) http authentication with nodejs using different authentication techniques. node-sp-auth also takes care about caching authentication data for performance (no need for you to think about how long authentication will be available, that's a task for node-sp-auth, as soon as authentication will be expired, node-sp-auth will renew it internally).

Versions supported:

  • SharePoint 2013 and onwards
  • SharePoint Online

Authentication options:

  • SharePoint 2013 and onwards:
    • Addin only permissions
    • User credentials through the http ntlm handshake
    • Form-based authentication (FBA)
    • Forefront TMG authentication
  • SharePoint Online:
    • Addin only permissions
    • SAML based with user credentials
  • ADFS user credentials (works with both SharePoint on-premise and Online)
  • On demand authentication. Uses interactive browser session for asking credentials. Supports third-party authentication providers for SharePoint Online and SharePoint on-premise. Doesn't support integrated windows authentication (NTLM).

Wiki contains detailed steps you need to perform in order to use any of authentication options as well as sample using.


How to use:

Install:

npm install node-sp-auth --save-dev

Create authentication headers and perform http request:

import * as spauth from 'node-sp-auth';
import * as request from 'request-promise';

//get auth options
spauth.getAuth(url, credentialOptions)
  .then(options => {

    //perform request with any http-enabled library (request-promise in a sample below):
    let headers = options.headers;
    headers['Accept'] = 'application/json;odata=verbose';

    request.get({
      url: 'https://[your tenant].sharepoint.com/sites/dev/_api/web',
      headers: headers
    }).then(response => {
      //process data
    });
  });

API:

getAuth(url, credentialOptions)

return value:

Promise resolving into object with following properties:

  • headers - http headers (normally contain Authorization header, may contain any other heraders as well)
  • options - any additional options you may need to include for succesful request. For example, in case of on premise user credentials authentication, you need to set agent property on corresponding http client

params:

  • url - required, string, url to SharePoint site, https://sp2013/sites/dev/ or https:/[your tenant].sharepoint.com/sites/dev/
  • credentialOptions - optional, object in a form of key-value. Each authentication option requires predefined credential object, depending on authentication type. Based on credentials provided, node-sp-auth automatically determines which authentication strategy to use (strategies listed in the top of the readme file).

Possible values for credentialOptions (depending on authentication strategy):

Please, use Wiki to see how you can configure your environment in order to use any of this authentication options.

setup(configuration)

params:

  • configuration - object accepting some configuration values for node-sp-auth. Currently it supports only configuration of underline request module via providing below code (for options available consider request repository):
spauth.setup({
   requestOptions: {... request options object}
 });

Development:

I recommend using VS Code for development. Repository already contains some settings for VS Code editor.

Before creating Pull Request you need to create an appropriate issue and reference it from PR.

  1. git clone https://github.com/s-KaiNet/node-sp-auth.git
  2. npm run build - runs linting and typescript compilation
  3. npm run dev - setup watchers and automatically runs typescript compilation, tslint and tests when you save files

Integration testing:

  1. Rename file /test/integration/config.sample.ts to config.ts.
  2. Update information in config.ts with appropriate values (urls, credentials).
  3. Run npm run test:integration.
  4. For tests debugging put a breakpoint and press F5 (works in VSCode only).

More Repositories

1

spfx-fast-serve

Improve your SharePoint Framework development flow by speeding up the "serve" command 🚀
TypeScript
135
star
2

sp-rest-explorer

Source code for SharePoint REST API Metadata Explorer
TypeScript
89
star
3

spsave

Save files in SharePoint using node.js easily
TypeScript
86
star
4

gulp-spsave

Gulp plugin for saving files inside SharePoint
JavaScript
52
star
5

sp-request

Simplified SharePoint HTTP client
TypeScript
52
star
6

modern-sharepoint-developer-roadmap

Roadmap for modern SharePoint developer
9
star
7

node-pnp-js

PnP-JS-Core (sp-pnp-js) with Node.js made easy
TypeScript
9
star
8

vscode-sp-typed-item

Generates TypeScript interfaces based on SharePoint data.
TypeScript
9
star
9

spfx-fast-serve-helpers

Contains helper classes and functions for spfx-fast-serve tool.
TypeScript
8
star
10

SPListRepository.js

Repository pattern implementation for convenient list data access through the SharePoint JavaScript client object model.
JavaScript
7
star
11

node-pnpjs-sample

This repository contains sample using pnp-js library with nodejs
TypeScript
7
star
12

sphooks

Cross-platform CLI for managing SharePoint list web hooks
JavaScript
4
star
13

spfx-fix-node10

Quick fix to run SPFx 1.7 on node10.x
JavaScript
4
star
14

expressjs-sp-addin

SharePoint add-in with Express.js and PnP-JS-Core
TypeScript
4
star
15

SharePoint-AspNet-Authentication

SharePoint add-in authentication middleware for Asp.Net MVC (both Asp.Net Core and Asp.Net MVC 5 via Owin)
C#
4
star
16

pnp-dev-resources

PnP developer resources
4
star
17

SharePoint-RER-with-Azure-Function-TypeScript

Sample on implementing SharePoint Remote Event Receiver with Azure Function written in TypeScript
TypeScript
4
star
18

react-simple-hook-store

Simple React hook based state management
TypeScript
3
star
19

spfx-check-locale

Check the consistency of your localization files inside SharePoint Framework projects.
TypeScript
3
star
20

passport-sharepoint-addin

Passport.js authentication middleware for SharePoint add-in
TypeScript
3
star
21

node-spoauth

Authenticate in SharePoint Online with node.js
JavaScript
2
star
22

time-zone-manager

TimeZoneManager is a sample web application built with ASP.NET Core and Vue.js
C#
2
star
23

sp-webpack-dev-proxy

Sample webpack http dev proxy setup which routes requests to SharePoint REST API
TypeScript
2
star
24

spfx-vue-sfc-one-file

Sample on implementing SPFx web part with Vue's single file component approach when all .vue artefacts (code, template, styles) are in a single .vue file
HTML
2
star
25

spfx-vue-hello-world

Hello World SharePoint Framework client web part with Vue.js
CSS
2
star
26

espc17-demos

Source code for demos at ESPC'17 "Building SharePoint Add-ins with PnP-JS-Core on a Client AND Server Side"
TypeScript
2
star
27

PnPjs-your-friend-demos

Sources for demos from "PnPjs - Your New SharePoint and Office 365 Development Friend" presentation
TypeScript
2
star
28

vsts-pnp-powershell

PnP-PowerShell VSTS build step
TypeScript
2
star
29

vue-ts-sfc-webpack-hmr

Sample starter for VueJS+TypeScript+SFC+HMR
JavaScript
1
star
30

vue-pnpjs

Vue.js and PnP.js integration plugin
TypeScript
1
star
31

gulp-jasmine-inject

Gulp plugin for injecting and runing jasmine tests in any working web site
JavaScript
1
star
32

StackAnalysis

Source code for program used to grab data for SP SE analysis
C#
1
star
33

pnpm-fast-serve-ws-test

JavaScript
1
star
34

sp-typed-item

Node.js module, CLI and VSCode extension for generating TypeScript interfaces based on SharePoint data.
TypeScript
1
star
35

SPAsyncScript

SPAsyncScript lets you implement SharePoint Script On Demand (SOD) easily
JavaScript
1
star