typed-rest-client
Advanced tools
Comparing version 1.7.1 to 1.7.2
@@ -13,3 +13,3 @@ "use strict"; | ||
prepareRequest(options) { | ||
options.headers['Authorization'] = 'Basic ' + new Buffer(this.username + ':' + this.password).toString('base64'); | ||
options.headers['Authorization'] = `Basic ${Buffer.from(`${this.username}:${this.password}`).toString('base64')}`; | ||
options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; | ||
@@ -16,0 +16,0 @@ } |
@@ -12,3 +12,3 @@ "use strict"; | ||
prepareRequest(options) { | ||
options.headers['Authorization'] = 'Bearer ' + this.token; | ||
options.headers['Authorization'] = `Bearer ${this.token}`; | ||
options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; | ||
@@ -15,0 +15,0 @@ } |
@@ -8,3 +8,3 @@ "use strict"; | ||
const _ = require("underscore"); | ||
const ntlm = require("../opensource/node-http-ntlm/ntlm"); | ||
const ntlm = require("../opensource/Node-SMB/lib/ntlm"); | ||
class NtlmCredentialHandler { | ||
@@ -15,14 +15,4 @@ constructor(username, password, workstation, domain) { | ||
this._ntlmOptions.password = password; | ||
if (domain !== undefined) { | ||
this._ntlmOptions.domain = domain; | ||
} | ||
else { | ||
this._ntlmOptions.domain = ''; | ||
} | ||
if (workstation !== undefined) { | ||
this._ntlmOptions.workstation = workstation; | ||
} | ||
else { | ||
this._ntlmOptions.workstation = ''; | ||
} | ||
this._ntlmOptions.domain = domain || ''; | ||
this._ntlmOptions.workstation = workstation || ''; | ||
} | ||
@@ -41,9 +31,3 @@ prepareRequest(options) { | ||
const wwwAuthenticate = response.message.headers['www-authenticate']; | ||
if (wwwAuthenticate) { | ||
const mechanisms = wwwAuthenticate.split(', '); | ||
const index = mechanisms.indexOf("NTLM"); | ||
if (index >= 0) { | ||
return true; | ||
} | ||
} | ||
return wwwAuthenticate && (wwwAuthenticate.split(', ').indexOf("NTLM") >= 0); | ||
} | ||
@@ -74,8 +58,5 @@ return false; | ||
}); | ||
if (httpClient.isSsl === true) { | ||
requestInfo.options.agent = new https.Agent({ keepAlive: true }); | ||
} | ||
else { | ||
requestInfo.options.agent = new http.Agent({ keepAlive: true }); | ||
} | ||
requestInfo.options.agent = httpClient.isSsl ? | ||
new https.Agent({ keepAlive: true }) : | ||
new http.Agent({ keepAlive: true }); | ||
let self = this; | ||
@@ -93,3 +74,3 @@ // The following pattern of sending the type1 message following immediately (in a setImmediate) is | ||
// If setImmediate is removed then the NTLM handshake will not work. | ||
// setImmediate allows us to queue a second request on the same connection. If this second | ||
// setImmediate allows us to queue a second request on the same connection. If this second | ||
// request is not queued on the connection when the first request finishes then node closes | ||
@@ -105,3 +86,4 @@ // the connection. NTLM requires both requests to be on the same connection so we need this. | ||
sendType1Message(httpClient, requestInfo, objs, finalCallback) { | ||
const type1msg = ntlm.createType1Message(this._ntlmOptions); | ||
const type1HexBuffer = ntlm.encodeType1(this._ntlmOptions.workstation, this._ntlmOptions.domain); | ||
const type1msg = `NTLM ${type1HexBuffer.toString('base64')}`; | ||
const type1options = { | ||
@@ -126,7 +108,25 @@ headers: { | ||
} | ||
const type2msg = ntlm.parseType2Message(res.message.headers['www-authenticate']); | ||
const type3msg = ntlm.createType3Message(type2msg, this._ntlmOptions); | ||
/** | ||
* Server will respond with challenge/nonce | ||
* assigned to response's "WWW-AUTHENTICATE" header | ||
* and should adhere to RegExp /^NTLM\s+(.+?)(,|\s+|$)/ | ||
*/ | ||
const serverNonceRegex = /^NTLM\s+(.+?)(,|\s+|$)/; | ||
const serverNonce = Buffer.from((res.message.headers['www-authenticate'].match(serverNonceRegex) || [])[1], 'base64'); | ||
let type2msg; | ||
/** | ||
* Wrap decoding the Server's challenge/nonce in | ||
* try-catch block to throw more comprehensive | ||
* Error with clear message to consumer | ||
*/ | ||
try { | ||
type2msg = ntlm.decodeType2(serverNonce); | ||
} | ||
catch (error) { | ||
throw new Error(`Decoding Server's Challenge to Obtain Type2Message failed with error: ${error.message}`); | ||
} | ||
const type3msg = ntlm.encodeType3(this._ntlmOptions.username, this._ntlmOptions.workstation, this._ntlmOptions.domain, type2msg, this._ntlmOptions.password).toString('base64'); | ||
const type3options = { | ||
headers: { | ||
'Authorization': type3msg, | ||
'Authorization': `NTLM ${type3msg}`, | ||
'Connection': 'Close' | ||
@@ -133,0 +133,0 @@ }, |
@@ -12,3 +12,3 @@ "use strict"; | ||
prepareRequest(options) { | ||
options.headers['Authorization'] = 'Basic ' + new Buffer('PAT:' + this.token).toString('base64'); | ||
options.headers['Authorization'] = `Basic ${Buffer.from(`PAT:${this.token}`).toString('base64')}`; | ||
options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; | ||
@@ -15,0 +15,0 @@ } |
@@ -75,3 +75,5 @@ "use strict"; | ||
} | ||
resolve(buffer.toString(encodingCharset)); | ||
else { | ||
resolve(buffer.toString(encodingCharset)); | ||
} | ||
}); | ||
@@ -290,3 +292,2 @@ }).on('error', function (err) { | ||
let socket; | ||
let isDataString = typeof (data) === 'string'; | ||
if (typeof (data) === 'string') { | ||
@@ -312,3 +313,3 @@ info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8'); | ||
if (socket) { | ||
socket.end(); | ||
socket.destroy(); | ||
} | ||
@@ -315,0 +316,0 @@ handleResult(new Error('Request timeout: ' + info.options.path), null); |
{ | ||
"name": "typed-rest-client", | ||
"version": "1.7.1", | ||
"version": "1.7.2", | ||
"description": "Node Rest and Http Clients for use with TypeScript", | ||
@@ -44,5 +44,5 @@ "main": "./RestClient.js", | ||
"qs": "^6.9.1", | ||
"tunnel": "0.0.4", | ||
"tunnel": "0.0.6", | ||
"underscore": "1.8.3" | ||
} | ||
} |
@@ -27,3 +27,3 @@ /// <reference types="node" /> | ||
*/ | ||
constructor(userAgent: string, baseUrl?: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions); | ||
constructor(userAgent: string | null | undefined, baseUrl?: string, handlers?: ifm.IRequestHandler[], requestOptions?: ifm.IRequestOptions); | ||
private _baseUrl; | ||
@@ -30,0 +30,0 @@ /** |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28
153889
1
1655
+ Addedtunnel@0.0.6(transitive)
- Removedtunnel@0.0.4(transitive)
Updatedtunnel@0.0.6