Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ script:
# Run test script, depending on istanbul install
- "test ! -z $(npm -ps ls istanbul) || npm test"
- "test -z $(npm -ps ls istanbul) || npm run-script test-travis"
- "test -z $(npm -ps ls eslint) || npm run-script lint"
# - "test -z $(npm -ps ls eslint) || npm run-script lint"
after_script:
- "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"

13 changes: 6 additions & 7 deletions digest-fetch-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

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')
const cryptojs = require('crypto-js')
const md5 = require('md5')
const base64 = require('base-64')

const supported_algorithms = ['MD5', 'MD5-sess']
Expand Down Expand Up @@ -83,7 +82,7 @@ class DigestClient {
}

static computeHash(user, realm, password) {
return cryptojs.MD5(`${user}:${realm}:${password}`).toString();
return md5(`${user}:${realm}:${password}`);
}

addAuth (url, options) {
Expand All @@ -99,7 +98,7 @@ class DigestClient {

let ha1 = this.precomputedHash ? this.password : DigestClient.computeHash(this.user, this.digest.realm, this.password)
if (this.digest.algorithm === 'MD5-sess') {
ha1 = cryptojs.MD5(`${ha1}:${this.digest.nonce}:${this.digest.cnonce}`).toString()
ha1 = md5(`${ha1}:${this.digest.nonce}:${this.digest.cnonce}`);
}

// optional MD5(entityBody) for 'auth-int'
Expand All @@ -108,15 +107,15 @@ class DigestClient {
// not implemented for auth-int
if (this.logger) this.logger.warn('Sorry, auth-int is not implemented in this plugin')
// const entityBody = xxx
// _ha2 = ':' + cryptojs.MD5(entityBody).toString()
// _ha2 = ':' + md5(entityBody)
}
const ha2 = cryptojs.MD5(`${method}:${uri}${_ha2}`).toString()
const ha2 = md5(`${method}:${uri}${_ha2}`);

const ncString = ('00000000'+this.digest.nc).slice(-8)

let _response = `${ha1}:${this.digest.nonce}:${ncString}:${this.digest.cnonce}:${this.digest.qop}:${ha2}`
if (!this.digest.qop) _response = `${ha1}:${this.digest.nonce}:${ha2}`
const response = cryptojs.MD5(_response).toString()
const response = md5(_response);

const opaqueString = this.digest.opaque !== null ? `opaque="${this.digest.opaque}",` : ''
const qopString = this.digest.qop ? `qop="${this.digest.qop}",` : ''
Expand Down
26 changes: 8 additions & 18 deletions digest-fetch.js

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digest-fetch",
"version": "1.1.6",
"version": "1.2.0",
"description": "digest auth request plugin for fetch/node-fetch also support http basic auth authentication",
"main": "digest-fetch-src.js",
"scripts": {
Expand All @@ -26,29 +26,27 @@
"url": "git+https://github.com/devfans/digest-fetch.git"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"after": "^0.8.2",
"babel-loader": "^8.0.4",
"babel-loader": "^8.2.2",
"babel-polyfill": "^6.26.0",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"eslint": "^5.9.0",
"eslint-plugin-markdown": "^1.0.0-rc.0",
"eslint": "^7.26.0",
"express": "^4.17.1",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^8.1.1",
"node-fetch": "^2.6.1",
"passport": "^0.4.0",
"passport-http": "^0.3.0",
"serialize-javascript": "^3.1.0",
"terser-webpack-plugin": "^2.2.2",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
},
"homepage": "https://github.com/devfans/digest-fetch#readme",
"dependencies": {
"base-64": "^0.1.0",
"crypto-js": "^3.1.9-1"
"md5": "^2.3.0"
}
}