Need private packages and team management tools?Check out npm Teams »


1.1.1 • Public • Published


Join the chat at NPM Version NPM Downloads Build Status Test Coverage

digest auth request plugin for fetch/node-fetch also supports http basic authentication


// dependencies for node
npm install node-fetch

// for browers, if to use it directly, please indcude file `digest-fetch.js` in a <script/> 
<script type="application/javascript" src="path-to-digest-fetch.js'></script>

Get Started

const DigestFetch = require('digest-fetch')
// In browser: const DigestFetch = window.DigestFetch;

Initialize with option and credential

Create a digest authentication request client with default options

const client = new DigestFetch('user', 'password') 

Specify options for digest authentication

const client = new DigestFetch('user', 'password', { algorithm: 'MD5' }) 

Options fields:

field type default description
algorithm string 'MD5' algorithm to be used: 'MD5' or 'MD5-sess'
statusCode number 401 custom authentication failure code for avoiding browser prompt, see details below
cnonceSize number 32 length of the cnonce
logger object none logger for debug, can use console, default no logging
basic bool false switch to use basic authentication
precomputeHash bool false wether to attach hash of credentials to the client instance instead of raw credential


Create a client using basic authentication challenge

const basic_auth_client = new DigestFetch('user', 'password', { basic: true })

Do request same way as fetch or node-fetch

const url = ''
const options = {}
client.fetch(url, options)

Pass in refresh request options factory function for conditions options needs be refreshed when trying again. For example when posting with file stream:

const factory = () => ({ method: 'post', body: fs.createReadStream('path-to-file') })
client.fetch(url, {factory})


Digest authentication: This plugin is implemented following RFC2069 and RFC2617, supports http basic authentication as well!

Please open issues if you find bugs or meet problems during using this plugin.


npm i digest-fetch

DownloadsWeekly Downloads






Unpacked Size

470 kB

Total Files


Last publish


  • avatar