forked from extern/bruno
Merge pull request #1047 from n00o/bugfix/Digest_toUpperCase_Error
Fix(#1002): Digest Error
This commit is contained in:
commit
b715e917fe
@ -1,4 +1,5 @@
|
||||
const crypto = require('crypto');
|
||||
const { URL } = require('url');
|
||||
|
||||
function isStrPresent(str) {
|
||||
return str && str !== '' && str !== 'undefined';
|
||||
@ -52,17 +53,20 @@ function addDigestInterceptor(axiosInstance, request) {
|
||||
const nonceCount = '00000001';
|
||||
const cnonce = crypto.randomBytes(24).toString('hex');
|
||||
|
||||
if (authDetails.algorithm.toUpperCase() !== 'MD5') {
|
||||
if (authDetails.algorithm && authDetails.algorithm.toUpperCase() !== 'MD5') {
|
||||
console.warn(`Unsupported Digest algorithm: ${algo}`);
|
||||
return Promise.reject(error);
|
||||
} else {
|
||||
authDetails.algorithm = 'MD5';
|
||||
}
|
||||
const uri = new URL(request.url).pathname;
|
||||
const HA1 = md5(`${username}:${authDetails['Digest realm']}:${password}`);
|
||||
const HA2 = md5(`${request.method}:${request.url}`);
|
||||
const HA2 = md5(`${request.method}:${uri}`);
|
||||
const response = md5(`${HA1}:${authDetails.nonce}:${nonceCount}:${cnonce}:auth:${HA2}`);
|
||||
|
||||
const authorizationHeader =
|
||||
`Digest username="${username}",realm="${authDetails['Digest realm']}",` +
|
||||
`nonce="${authDetails.nonce}",uri="${request.url}",qop="auth",algorithm="${authDetails.algorithm}",` +
|
||||
`nonce="${authDetails.nonce}",uri="${uri}",qop="auth",algorithm="${authDetails.algorithm}",` +
|
||||
`response="${response}",nc="${nonceCount}",cnonce="${cnonce}"`;
|
||||
originalRequest.headers['Authorization'] = authorizationHeader;
|
||||
console.debug(`Authorization: ${originalRequest.headers['Authorization']}`);
|
||||
|
Loading…
Reference in New Issue
Block a user