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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 3.7.1
#### Bug Fix
- https://github.com/marklogic/node-client-api/issues/961

## 3.7.0
#### New Functionality

Expand Down
2 changes: 1 addition & 1 deletion lib/requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright © 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
'use strict';
var createAuthInitializer = require('www-authenticate');
var createAuthInitializer = require('./www-authenticate-patched/www-authenticate');
var Kerberos = require('./optional.js')
.libraryProperty('kerberos', 'Kerberos');
var Multipart = require('multipart-stream');
Expand Down
18 changes: 18 additions & 0 deletions lib/www-authenticate-patched/md5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* www-authenticate
* https://github.com/randymized/www-authenticate
*
* Copyright (c) 2013 Randy McLaughlin
* Licensed under the MIT license.
*/

/*
* Copyright © 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var crypto= require('crypto');

function md5(s) {
return crypto.createHash('md5').update(s).digest('hex');
}

module.exports= md5;
118 changes: 118 additions & 0 deletions lib/www-authenticate-patched/parsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* www-authenticate
* https://github.com/randymized/www-authenticate
*
* Copyright (c) 2013 Randy McLaughlin
* Licensed under the MIT license.
*/

/*
* Copyright © 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var ParseAuth= /(\w+)\s+(.*)/ // -> scheme, params
, Separators= /([",=])/
;

function parse_params(header) {
// This parser will definitely fail if there is more than one challenge
var tok, _i, _len, key, value;
var state= 0; //0: token,
var m= header.split(Separators)
for (_i = 0, _len = m.length; _i < _len; _i++) {
tok = m[_i];
if (!tok.length) continue;
switch (state) {
case 0: // token
key= tok.trim();
state= 1; // expect equals
continue;
case 1: // expect equals
if ('=' != tok) return 'Equal sign was expected after '+key;
state= 2;
continue;
case 2: // expect value
if ('"' == tok) {
value= '';
state= 3; // expect quoted
continue;
}
else {
this.parms[key]= value= tok.trim();
state= 9; // expect comma or end
continue;
}
case 3: // handling quoted string
if ('"' == tok) {
state= 8; // end quoted
continue;
}
else {
value+= tok;
state= 3; // continue accumulating quoted string
continue;
}
case 8: // end quote encountered
if ('"' == tok) {
// double quoted
value+= '"';
state= 3; // back to quoted string
continue;
}
if (',' == tok) {
this.parms[key]= value;
state= 0;
continue;
}
else {
return 'Unexpected token ('+tok+') after '+value+'"';
}
case 9: // expect commma
if (',' != tok) return 'Comma expected after '+value;
state= 0;
continue;
}
}
switch (state) { // terminal state
case 0: // Empty or ignoring terminal comma
case 9: // Expecting comma or end of header
return;
case 8: // Last token was end quote
this.parms[key]= value;
return;
default:
return 'Unexpected end of www-authenticate value.';
}
}

function Parse_WWW_Authenticate(to_parse)
{
var m= to_parse.match(ParseAuth);
this.scheme= m[1];
this.parms= {};
var err= this.parse_params(m[2]);
if (err) {
this.scheme= '';
this.parms= {};
this.err= err;
}
}

function Parse_Authentication_Info(to_parse)
{
this.scheme= 'Digest';
this.parms= {};
var err= this.parse_params(to_parse);
if (err) {
this.scheme= '';
this.parms= {};
this.err= err;
}
}

Parse_Authentication_Info.prototype.parse_params= parse_params;
Parse_WWW_Authenticate.prototype.parse_params= parse_params;

module.exports = {
WWW_Authenticate: Parse_WWW_Authenticate,
Authentication_Info: Parse_Authentication_Info
};
57 changes: 57 additions & 0 deletions lib/www-authenticate-patched/user-credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* www-authenticate
* https://github.com/randymized/www-authenticate
*
* Copyright (c) 2013 Randy McLaughlin
* Licensed under the MIT license.
*/

/*
* Copyright © 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var md5= require('./md5');

/*
* Hide the password. Uses the password to form authorization strings,
* but provides no interface for exporting it.
*/
function user_credentials(username,password,options) {
if (username.is_user_credentials &&
typeof username.basic === 'function' &&
typeof username.digest === 'function'
) {
return username;
}

var basic_string= options && options.hide_basic ?
''
:
(!password && password !== '' ?
Buffer.from(username, "ascii").toString("base64")
:
Buffer.from(username+':'+password, "ascii").toString("base64")
)
function Credentials()
{
this.username= username;
}
Credentials.prototype.basic= function()
{
return basic_string;
}
Credentials.prototype.digest= function(realm)
{
return !password && password !== '' ?
md5(username+':'+realm)
:
md5(username+':'+realm+':'+password)
}
Credentials.prototype.is_user_credentials= function()
{
return true;
}

return new Credentials;
}

module.exports= user_credentials;
Loading
Loading