Socket
Socket
Sign inDemoInstall

digest-fetch

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

digest-fetch - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

15

digest-fetch-src.js
const canRequire = typeof(require) == 'function'
if (typeof(fetch) !== 'function' && canRequire) var fetch = require('node-fetch')
if (typeof(cryptojs) !== 'function' && canRequire) var cryptojs = require('crypto-js')
// if (typeof(cryptojs) !== 'function' && canRequire) var cryptojs = require('crypto-js')
const cryptojs = require('crypto-js')

@@ -36,3 +37,3 @@ class DigestClient {

addAuth (url, options) {
if (typeof(options.renew) == 'function') options = options.renew()
if (typeof(options.factory) == 'function') options = options.factory()
if (!this.hasAuth) return options

@@ -44,5 +45,5 @@ if (this.logger) this.logger.info(`requesting with auth carried`)

const ha1 = cryptojs.MD5(`${this.user}:${this.digest.realm}:${this.password}`).toString()
const ha2 = cryptojs.MD5(`${method}:${uri}`).toString()
const ha2 = cryptojs.MD5(`${method}:${uri}`).toString()
const ncString = ('00000000'+this.digest.nc).slice(-8)
const response = cryptojs.MD5(`${ha1}:${this.digest.nonce}:${ncString}:${this.digest.cnonce}:${this.digest.qop}:${ha2}`).toString()
const response = cryptojs.MD5(`${ha1}:${this.digest.nonce}:${ncString}:${this.digest.cnonce}:${this.digest.qop}:${ha2}`).toString()
const opaqueString = this.digest.opaque? `opaque="${this.digest.opaque}",` : ''

@@ -57,7 +58,7 @@ const digest = `${this.digest.scheme} username="${this.user}",realm="${this.digest.realm}",\

}
// const {renew, ..._options} = options
// const {factory, ..._options} = options
const _options = {}
Object.assign(_options, options)
delete _options.renew
return _options;
delete _options.factory
return _options;
}

@@ -64,0 +65,0 @@

{
"name": "digest-fetch",
"version": "0.0.7",
"version": "0.1.0",
"description": "digest auth request plugin for fetch/node-fetch",

@@ -5,0 +5,0 @@ "main": "digest-fetch-src.js",

# digest-fetch
[![Join the chat at https://gitter.im/devfans/digest-fetch](https://badges.gitter.im/devfans/digest-fetch.svg)](https://gitter.im/devfans/digest-fetch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![NPM Version][npm-image]][npm-url]

@@ -14,6 +16,4 @@ [![NPM Downloads][downloads-image]][downloads-url]

// dependencies for browser
<script src='path-to-crypto-js.js'></script>
npm install digest-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>
```

@@ -40,6 +40,6 @@

// pass in refresh request options function for conditions options needs be refreshed when trying again.
// pass in refresh request options factory function for conditions options needs be refreshed when trying again.
// etc: when posting with file stream
const renew = () => ({ method: 'post', body: fs.createReadStream('path-to-file') })
client.fetch(url, {renew})
const factory = () => ({ method: 'post', body: fs.createReadStream('path-to-file') })
client.fetch(url, {factory})
.then(resp=>resp.json())

@@ -46,0 +46,0 @@ .then(data=>console.log(data))

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc