Skip to content

Commit

Permalink
treat the access token as a secret, do not export it
Browse files Browse the repository at this point in the history
Transfer token from previous versions.
  • Loading branch information
codeworkx authored and dirkjanfaber committed Dec 31, 2023
1 parent 9d45584 commit 0b21583
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/nodes/config-vrm-api.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<script type="text/javascript">
RED.nodes.registerType('config-vrm-api',{
category: 'config',
credentials: {
token: {
type: 'password',
validate: RED.validators.regex(/^[a-z0-9]{64}$/)
},
},
defaults: {
name: { value: "" },
token: { value: "", validate: RED.validators.regex(/^[a-z0-9]{64}$/) }
name: { value: "" }
},
label: function() {
return this.name || 'VRM API';
Expand Down
28 changes: 21 additions & 7 deletions src/nodes/config-vrm-api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
module.exports = function (RED) {
'use strict'
function ConfigVRMAPI (n) {
RED.nodes.createNode(this, n)
this.name = n.name
this.token = n.token
}
RED.nodes.registerType('config-vrm-api', ConfigVRMAPI)
'use strict'
function ConfigVRMAPI (config) {
RED.nodes.createNode(this, config);
this.name = config.name;

// Transfer data from previous versions
if (this.credentials && !this.credentials.token && config.token) {
RED.nodes.addCredentials(this.id, { token: config.token });
}

// Delete deprecated properties
delete config.token;
delete this.token;
}
RED.nodes.registerType('config-vrm-api', ConfigVRMAPI, {
credentials: {
token: {
type: 'password'
},
},
});
}
2 changes: 1 addition & 1 deletion src/nodes/vrm-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
paletteLabel: 'VRM API',
color: '#f7ab3e',
defaults: {
vrm: {value:"", type: "config-vrm-api"},
vrm: {value: "", type: "config-vrm-api"},
name: { value: "" },
idSite: { value: "", validate: RED.validators.regex(/^[0-9]{1,12}$/)},
installations: { value: "", required: true},
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/vrm-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function (RED) {
const options = {
}
const headers = {
'X-Authorization': 'Token ' + this.vrm.token,
'X-Authorization': 'Token ' + this.vrm.credentials.token,
accept: 'application/json',
'User-Agent': 'nrc-vrm-api/' + packageJson.version
}
Expand Down

0 comments on commit 0b21583

Please sign in to comment.