diff --git a/packages/node_modules/@node-red/nodes/core/io/21-httprequest.html b/packages/node_modules/@node-red/nodes/core/io/21-httprequest.html index a9c0f5544..5cf8f63e0 100644 --- a/packages/node_modules/@node-red/nodes/core/io/21-httprequest.html +++ b/packages/node_modules/@node-red/nodes/core/io/21-httprequest.html @@ -49,11 +49,19 @@
+ + +
+
- +
@@ -93,7 +101,8 @@ paytoqs: {value: false}, url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} }, tls: {type:"tls-config",required: false}, - proxy: {type:"http proxy",required: false} + proxy: {type:"http proxy",required: false}, + authType: {value: "basic"} }, credentials: { user: {type:"text"}, @@ -115,12 +124,29 @@ $("#node-input-useAuth").change(function() { if ($(this).is(":checked")) { $(".node-input-useAuth-row").show(); + // Nodes (< version 0.20.x) with credentials but without authentication type, need type 'basic' + if (!$('#node-input-authType').val()) { + $('#node-input-authType').val('basic'); + } } else { $(".node-input-useAuth-row").hide(); + $('#node-input-authType').val(''); $('#node-input-user').val(''); $('#node-input-password').val(''); } }); + $("#node-input-authType").change(function() { + if ($(this).val() == "basic" || $(this).val() == "digest") { + $(".node-input-basic-row").show(); + $('#node-span-password').show(); + $('#node-span-token').hide(); + } else if ($(this).val() == "bearer") { + $(".node-input-basic-row").hide(); + $('#node-span-password').hide(); + $('#node-span-token').show(); + $('#node-input-user').val(''); + } + }); $("#node-input-method").change(function() { if ($(this).val() == "GET") { $(".node-input-paytoqs-row").show(); diff --git a/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js b/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js index cad6444a7..dae51ded7 100644 --- a/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js +++ b/packages/node_modules/@node-red/nodes/core/io/21-httprequest.js @@ -33,6 +33,7 @@ module.exports = function(RED) { var tlsNode = RED.nodes.getNode(n.tls); } this.ret = n.ret || "txt"; + this.authType = n.authType || "basic"; if (RED.settings.httpRequestTimeout) { this.reqTimeout = parseInt(RED.settings.httpRequestTimeout) || 120000; } else { this.reqTimeout = 120000; } @@ -175,11 +176,29 @@ module.exports = function(RED) { } } } - if (this.credentials && this.credentials.user) { - opts.auth = { - user: this.credentials.user, - pass: this.credentials.password||"" - }; + if (this.credentials) { + if (this.authType === "basic") { + if (this.credentials.user) { + opts.auth = { + user: this.credentials.user, + pass: this.credentials.password || "" + }; + } + } else if (this.authType === "digest") { + if (this.credentials.user) { + // The first request will be send without auth information. Based on the 401 response, the library can determine + // which auth type is required by the server. Then the request is resubmitted the with the appropriate auth header. + opts.auth = { + user: this.credentials.user, + pass: this.credentials.password || "", + sendImmediately: false + }; + } + } else if (this.authType === "bearer") { + opts.auth = { + bearer: this.credentials.password || "" + }; + } } var payload = null; diff --git a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json index d8a6a8d20..97cfdc303 100755 --- a/packages/node_modules/@node-red/nodes/locales/en-US/messages.json +++ b/packages/node_modules/@node-red/nodes/locales/en-US/messages.json @@ -380,12 +380,17 @@ "status": "Status code", "headers": "Headers", "other": "other", + "authType": "Type", + "bearerToken": "Token", "paytoqs" : "Append msg.payload as query string parameters" }, "setby": "- set by msg.method -", - "basicauth": "Use basic authentication", + "basicauth": "Use authentication", "use-tls": "Enable secure (SSL/TLS) connection", "tls-config":"TLS Configuration", + "basic": "basic authentication", + "digest": "digest authentication", + "bearer": "bearer authentication", "use-proxy": "Use proxy", "proxy-config": "Proxy Configuration", "use-proxyauth": "Use proxy authentication",