From 32a904394fb7596cee9342816b7d570fcc29a447 Mon Sep 17 00:00:00 2001 From: Harry Lachenmayer Date: Tue, 20 Oct 2015 19:42:19 +0100 Subject: [PATCH] Add HTTP basic authentication. --- lib/adapters/xhr.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index 5cf5429..4fc7b86 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -39,10 +39,17 @@ module.exports = function xhrAdapter(resolve, reject, config) { xDomain = true; } + // HTTP basic authentication + var configAuth = config.auth || {}; + var auth = { + username: configAuth.username || configAuth.user || '', + password: configAuth.password || configAuth.pass || '' + }; + // Create the request var request = new adapter('Microsoft.XMLHTTP'); - request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true); - + request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true, auth.username, auth.password); + // Set the request timeout in MS request.timeout = config.timeout;