npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pnp-auth

v2.0.0

Published

Provides additional authentication options for @pnp/pnpjs (aka PnPjs) library

Downloads

2,712

Readme

pnp-auth adds additional authentication options for PnPjs library via implementing custom NodeFetchClient

NPM

npm version Downloads Gitter chat

!Important: as library implements NodeFetchClient and depends on node-sp-auth module, you can use pnp-auth only in nodejs environment

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 and onwards
  • SharePoint Online

For full list of authentication options check out node-sp-auth readme.

How to use

Install

Note on PnPjs v1 usage

If you need support for the previous version of PnPjs, simply install the version of pnp-auth, which supports PnPjs v1:

npm install [email protected]

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-commonjs';

bootstrap(sp, authData, siteUrl);
// That's it! Now you can use pnp-sp library:

sp.web.get().then(...);

OR with factory methods:

import { bootstrap } from 'pnp-auth';
import { sp, Web } from '@pnp/sp-commonjs';

bootstrap(sp, authData); 
// That's it! Now you can use pnp-sp library:

let web = Web(siteUrl);
web.get().then(...)

API:

bootstrap(sp, authData, siteUrl)

  • sp - "sp" object obtained from @pnp/sp-commonjs library via import: import { sp } from '@pnp/sp-commonjs';
  • authData - can be a string, AuthConfig object or raw node-sp-auth credentials:
    • string - absolute or relative path to your file with authentication data. File should be generated using node-sp-auth-config CLI. When string is provided, pnp-auth internally creates AuthConfig with below default parameters:
    let authConfig = new AuthConfig({
      configPath: <your path to file>,
      encryptPassword: true,
      saveConfigOnDisk: true
    });
    • AuthConfig - you can provide AuthConfig directly. To learn more checkout node-sp-auth-config repository
    • raw credentials - you can pass any credential options which are supported by node-sp-auth. For more information checkout node-sp-auth repository as well as wiki
  • siteUrl - your SharePoint site url. You have two options when working with SharePoint data. When using siteUrl parameter, you can write a code sp.web.get() etc., in that case your sp.web object will be attached to your siteUrl. If you want to work with different webs, you can use factory method: Web(<url to SharePoint>)

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-commonjs';

sp.setup({
  sp: {
    fetchClientFactory: () => {
      return new NodeFetchClient(authData, siteUrl);
    }
  }
});

Development

  1. npm install
  2. npm run build - tslint & TS compile

Testing

Library has a few integration tests:

  1. npm install
  2. Rename settings.sample.ts to settings.ts. Update webTitle and subsiteUrl to your real data.
  3. 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.
  4. Run npm test