@node-red/editor-api 2.2.1 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ let runtimeAPI;
2
+ let settings;
3
+ const apiUtil = require("../util");
4
+ module.exports = {
5
+ init: function(_settings, _runtimeAPI) {
6
+ settings = _settings;
7
+ runtimeAPI = _runtimeAPI;
8
+ },
9
+ getReport: function(req, res) {
10
+ const diagnosticsOpts = settings.diagnostics || {};
11
+ const opts = {
12
+ user: req.user,
13
+ scope: diagnosticsOpts.level || "basic"
14
+ }
15
+ if(diagnosticsOpts.enabled === false || diagnosticsOpts.enabled === "false") {
16
+ apiUtil.rejectHandler(req, res, {message: "diagnostics are disabled", status: 403, code: "diagnostics.disabled" })
17
+ } else {
18
+ runtimeAPI.diagnostics.get(opts)
19
+ .then(function(result) { res.json(result); })
20
+ .catch(err => apiUtil.rejectHandler(req, res, err))
21
+ }
22
+ }
23
+ }
@@ -23,6 +23,7 @@ var context = require("./context");
23
23
  var auth = require("../auth");
24
24
  var info = require("./settings");
25
25
  var plugins = require("./plugins");
26
+ var diagnostics = require("./diagnostics");
26
27
 
27
28
  var apiUtil = require("../util");
28
29
 
@@ -34,6 +35,7 @@ module.exports = {
34
35
  context.init(runtimeAPI);
35
36
  info.init(settings,runtimeAPI);
36
37
  plugins.init(runtimeAPI);
38
+ diagnostics.init(settings, runtimeAPI);
37
39
 
38
40
  var needsPermission = auth.needsPermission;
39
41
 
@@ -95,6 +97,8 @@ module.exports = {
95
97
  adminApp.get("/plugins", needsPermission("plugins.read"), plugins.getAll, apiUtil.errorHandler);
96
98
  adminApp.get("/plugins/messages", needsPermission("plugins.read"), plugins.getCatalogs, apiUtil.errorHandler);
97
99
 
100
+ adminApp.get("/diagnostics", needsPermission("diagnostics.read"), diagnostics.getReport, apiUtil.errorHandler);
101
+
98
102
  return adminApp;
99
103
  }
100
104
  }
package/lib/auth/index.js CHANGED
@@ -106,9 +106,15 @@ async function login(req,res) {
106
106
  urlPrefix += "/";
107
107
  }
108
108
  response = {
109
- "type":"strategy",
110
- "prompts":[{type:"button",label:mergedAdminAuth.strategy.label, url: urlPrefix + "auth/strategy"}]
109
+ "type":"strategy"
111
110
  }
111
+ if (mergedAdminAuth.strategy.autoLogin) {
112
+ response.autoLogin = true
113
+ response.loginRedirect = urlPrefix + "auth/strategy"
114
+ }
115
+ response.prompts = [
116
+ {type:"button",label:mergedAdminAuth.strategy.label, url: urlPrefix + "auth/strategy"}
117
+ ]
112
118
  if (mergedAdminAuth.strategy.icon) {
113
119
  response.prompts[0].icon = mergedAdminAuth.strategy.icon;
114
120
  }
@@ -185,7 +191,7 @@ function genericStrategy(adminApp,strategy) {
185
191
  }
186
192
  };
187
193
 
188
- options.verify.apply(null,args);
194
+ options.verify.apply(this,args);
189
195
  } else {
190
196
  var profile = arguments[arguments.length - 2];
191
197
  return completeVerify(profile,originalDone);
@@ -92,10 +92,16 @@ var passwordTokenExchange = function(client, username, password, scope, done) {
92
92
  loginAttempts = loginAttempts.filter(function(logEntry) {
93
93
  return logEntry.user !== username;
94
94
  });
95
- Tokens.create(username,client.id,scope).then(function(tokens) {
96
- log.audit({event: "auth.login",user,username:username,client:client.id,scope:scope});
97
- done(null,tokens.accessToken,null,{expires_in:tokens.expires_in});
98
- });
95
+ // Check if the user contains a user defined token and use it
96
+ // instead of generating a new token
97
+ if(user.token){
98
+ done(null,user.token,null,null);
99
+ } else {
100
+ Tokens.create(username,client.id,scope).then(function(tokens) {
101
+ log.audit({event: "auth.login",user,username:username,client:client.id,scope:scope});
102
+ done(null,tokens.accessToken,null,{expires_in:tokens.expires_in});
103
+ });
104
+ }
99
105
  } else {
100
106
  log.audit({event: "auth.login.fail.permissions",username:username,client:client.id,scope:scope});
101
107
  done(null,false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/editor-api",
3
- "version": "2.2.1",
3
+ "version": "3.0.0-beta.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,14 +16,14 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/util": "2.2.1",
20
- "@node-red/editor-client": "2.2.1",
19
+ "@node-red/util": "3.0.0-beta.2",
20
+ "@node-red/editor-client": "3.0.0-beta.2",
21
21
  "bcryptjs": "2.4.3",
22
- "body-parser": "1.19.1",
22
+ "body-parser": "1.20.0",
23
23
  "clone": "2.1.2",
24
24
  "cors": "2.8.5",
25
- "express-session": "1.17.2",
26
- "express": "4.17.2",
25
+ "express-session": "1.17.3",
26
+ "express": "4.18.1",
27
27
  "memorystore": "1.6.7",
28
28
  "mime": "3.0.0",
29
29
  "multer": "1.4.4",