mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add Digest and Bearer Auth modes to http request node (#2061)
* Authentication methods * Authentication methods * Authentication methods * Support undefined auth type * Support undefined auth type * Apply basic auth on existing nodes * Use password as bearer token * Use password as bearer token * Switch between password/token labels * Bearer token abbreviation * Separate token span
This commit is contained in:
parent
f4f664a4a2
commit
e7b1ec6904
@ -49,11 +49,19 @@
|
|||||||
<label for="node-input-useAuth" style="width: 70%;"><span data-i18n="httpin.basicauth"></span></label>
|
<label for="node-input-useAuth" style="width: 70%;"><span data-i18n="httpin.basicauth"></span></label>
|
||||||
<div style="margin-left: 20px" class="node-input-useAuth-row hide">
|
<div style="margin-left: 20px" class="node-input-useAuth-row hide">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
<label for="node-input-authType"><i class="fa fa-user-secret "></i> <span data-i18n="httpin.label.authType"></span></label>
|
||||||
|
<select type="text" id="node-input-authType" style="width:70%;">
|
||||||
|
<option value="basic" data-i18n="httpin.basic"></option>
|
||||||
|
<option value="digest" data-i18n="httpin.digest"></option>
|
||||||
|
<option value="bearer" data-i18n="httpin.bearer"></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-row node-input-basic-row">
|
||||||
<label for="node-input-user"><i class="fa fa-user"></i> <span data-i18n="common.label.username"></span></label>
|
<label for="node-input-user"><i class="fa fa-user"></i> <span data-i18n="common.label.username"></span></label>
|
||||||
<input type="text" id="node-input-user">
|
<input type="text" id="node-input-user">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-password"><i class="fa fa-lock"></i> <span data-i18n="common.label.password"></span></label>
|
<label for="node-input-password"> <i class="fa fa-lock"></i> <span data-i18n="common.label.password" id="node-span-password"></span><span data-i18n="httpin.label.bearerToken" id="node-span-token" style="hide"></span></label>
|
||||||
<input type="password" id="node-input-password">
|
<input type="password" id="node-input-password">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -93,7 +101,8 @@
|
|||||||
paytoqs: {value: false},
|
paytoqs: {value: false},
|
||||||
url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
|
url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
|
||||||
tls: {type:"tls-config",required: false},
|
tls: {type:"tls-config",required: false},
|
||||||
proxy: {type:"http proxy",required: false}
|
proxy: {type:"http proxy",required: false},
|
||||||
|
authType: {value: "basic"}
|
||||||
},
|
},
|
||||||
credentials: {
|
credentials: {
|
||||||
user: {type:"text"},
|
user: {type:"text"},
|
||||||
@ -115,12 +124,29 @@
|
|||||||
$("#node-input-useAuth").change(function() {
|
$("#node-input-useAuth").change(function() {
|
||||||
if ($(this).is(":checked")) {
|
if ($(this).is(":checked")) {
|
||||||
$(".node-input-useAuth-row").show();
|
$(".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 {
|
} else {
|
||||||
$(".node-input-useAuth-row").hide();
|
$(".node-input-useAuth-row").hide();
|
||||||
|
$('#node-input-authType').val('');
|
||||||
$('#node-input-user').val('');
|
$('#node-input-user').val('');
|
||||||
$('#node-input-password').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() {
|
$("#node-input-method").change(function() {
|
||||||
if ($(this).val() == "GET") {
|
if ($(this).val() == "GET") {
|
||||||
$(".node-input-paytoqs-row").show();
|
$(".node-input-paytoqs-row").show();
|
||||||
|
@ -33,6 +33,7 @@ module.exports = function(RED) {
|
|||||||
var tlsNode = RED.nodes.getNode(n.tls);
|
var tlsNode = RED.nodes.getNode(n.tls);
|
||||||
}
|
}
|
||||||
this.ret = n.ret || "txt";
|
this.ret = n.ret || "txt";
|
||||||
|
this.authType = n.authType || "basic";
|
||||||
if (RED.settings.httpRequestTimeout) { this.reqTimeout = parseInt(RED.settings.httpRequestTimeout) || 120000; }
|
if (RED.settings.httpRequestTimeout) { this.reqTimeout = parseInt(RED.settings.httpRequestTimeout) || 120000; }
|
||||||
else { this.reqTimeout = 120000; }
|
else { this.reqTimeout = 120000; }
|
||||||
|
|
||||||
@ -175,11 +176,29 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.credentials && this.credentials.user) {
|
if (this.credentials) {
|
||||||
opts.auth = {
|
if (this.authType === "basic") {
|
||||||
user: this.credentials.user,
|
if (this.credentials.user) {
|
||||||
pass: this.credentials.password||""
|
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;
|
var payload = null;
|
||||||
|
|
||||||
|
@ -380,12 +380,17 @@
|
|||||||
"status": "Status code",
|
"status": "Status code",
|
||||||
"headers": "Headers",
|
"headers": "Headers",
|
||||||
"other": "other",
|
"other": "other",
|
||||||
|
"authType": "Type",
|
||||||
|
"bearerToken": "Token",
|
||||||
"paytoqs" : "Append msg.payload as query string parameters"
|
"paytoqs" : "Append msg.payload as query string parameters"
|
||||||
},
|
},
|
||||||
"setby": "- set by msg.method -",
|
"setby": "- set by msg.method -",
|
||||||
"basicauth": "Use basic authentication",
|
"basicauth": "Use authentication",
|
||||||
"use-tls": "Enable secure (SSL/TLS) connection",
|
"use-tls": "Enable secure (SSL/TLS) connection",
|
||||||
"tls-config":"TLS Configuration",
|
"tls-config":"TLS Configuration",
|
||||||
|
"basic": "basic authentication",
|
||||||
|
"digest": "digest authentication",
|
||||||
|
"bearer": "bearer authentication",
|
||||||
"use-proxy": "Use proxy",
|
"use-proxy": "Use proxy",
|
||||||
"proxy-config": "Proxy Configuration",
|
"proxy-config": "Proxy Configuration",
|
||||||
"use-proxyauth": "Use proxy authentication",
|
"use-proxyauth": "Use proxy authentication",
|
||||||
|
Loading…
Reference in New Issue
Block a user