pnp-auth
adds additional authentication options for PnPjs library via implementing custom NodeFetchClient
![NPM](https://nodei.co/npm/pnp-auth.png?mini=true&downloads=true&downloadRank=true&stars=true)
![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)
pnp-auth
uses node-sp-auth
as authentication library, thus making all authentication options from node-sp-auth
available for pnp-auth
.
Supported versions:
- SharePoint 2013, 2016, 2019
- SharePoint Online
For full list of authentication options check out node-sp-auth
readme.
How to use
Install
Install @pnp/sp
libraries (they are listed as peer dependencies for pnp-auth
, that's why you should install them separately).
We need more than just @pnp/sp
because it depends on some other @pnp/
packages:
npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp --save
Install pnp-auth
:
npm install pnp-auth --save
Bootstrap
Before using PnPjs library, you should make it aware of your authentication data. That should be performed at the start of your application. The code is fairly simple:
import { bootstrap } from 'pnp-auth';
import { sp } from '@pnp/sp';
bootstrap(sp, authData, siteUrl);
sp.web.get().then(...);
OR with object's constructors:
import { bootstrap } from 'pnp-auth';
import { sp, Web } from '@pnp/sp';
bootstrap(sp, authData);
let web = new Web(siteUrl);
web.get().then(...)
API:
bootstrap(sp, authData, siteUrl)
Manual bootstrap
Of course, you can do bootstrap manually, if you want. pnp-auth
exports NodeFetchClient
which you can use in pnp's setup
method:
import NodeFetchClient from 'pnp-auth';
import { sp } from '@pnp/sp';
sp.setup({
sp: {
fetchClientFactory: () => {
return new NodeFetchClient(authData, siteUrl);
}
}
});
Development
npm install
npm run build
- tslint & TS compile
Testing
Library has a few integration tests:
npm install
- Rename
settings.sample.ts
to settings.ts
. Update webTitle
and subsiteUrl
to your real data. - Use
node-sp-auth-config
to generate credentials inside ./config/private.json
file. Site url in credentials should point to site with webTitle
from step #2
. - Run
npm test