From 450888f54245a1beba8543386e3431c1cb454539 Mon Sep 17 00:00:00 2001 From: Ariel Ferreira Date: Sat, 26 Feb 2022 16:35:46 -0500 Subject: [PATCH] check if user contains token and use it instead of generating a new Token --- .../@node-red/editor-api/lib/auth/strategies.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/node_modules/@node-red/editor-api/lib/auth/strategies.js b/packages/node_modules/@node-red/editor-api/lib/auth/strategies.js index 879b3f55b..e18925c19 100644 --- a/packages/node_modules/@node-red/editor-api/lib/auth/strategies.js +++ b/packages/node_modules/@node-red/editor-api/lib/auth/strategies.js @@ -92,10 +92,16 @@ var passwordTokenExchange = function(client, username, password, scope, done) { loginAttempts = loginAttempts.filter(function(logEntry) { return logEntry.user !== username; }); - Tokens.create(username,client.id,scope).then(function(tokens) { - log.audit({event: "auth.login",user,username:username,client:client.id,scope:scope}); - done(null,tokens.accessToken,null,{expires_in:tokens.expires_in}); - }); + // Check if the user contains a user defined token and use it + // instead of generating a new token + if(user.token){ + done(null,user.token,null,null); + } else { + Tokens.create(username,client.id,scope).then(function(tokens) { + log.audit({event: "auth.login",user,username:username,client:client.id,scope:scope}); + done(null,tokens.accessToken,null,{expires_in:tokens.expires_in}); + }); + } } else { log.audit({event: "auth.login.fail.permissions",username:username,client:client.id,scope:scope}); done(null,false);