I am trying to use GitHub to authenticate users in node-red, I tried following the documentation, but there is not a lot of info.
I created a file named user-authentication.js, copied the OAuth strategy, and in setings.js I added adminAuth: require("./user-authentication"),
After trying to start node-red I get an error:
$ node-red
Error loading settings file: /home/nemanja/.node-red/settings.js
/home/nemanja/.node-red/user-authentication.js:3
strategy: {
^
SyntaxError: Unexpected token ':'
at Object.compileFunction (vm.js:344:18)
at wrapSafe (internal/modules/cjs/loader.js:1106:15)
at Module._compile (internal/modules/cjs/loader.js:1140:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
at Module.require (internal/modules/cjs/loader.js:1080:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/home/nemanja/.node-red/settings.js:123:16)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
Am I doing something wrong ? I can`t find any good info on how it should be implemented...
If you want to move some settings out to another file and then include them with a require statement, then that other file needs to be a node module. In other words it needs to look something like:
module.exports = {
type:"strategy",
strategy: {
...
}
}
My guess is you haven't got the module.exports= bit at the start of your file.
Node-Red started, but I am stuck at the login page seeing nothing, take a look...
The console doesn't show any error...
Should I edit something in settings file?
Here is my user-authentication file...
module.exports = {
adminAuth: {
type:"strategy",
strategy: {
name: "twitter",
label: 'Sign in with Twitter',
icon:"fa-twitter",
strategy: require("passport-twitter").Strategy,
options: {
consumerKey: 'Iv1.2XXXXXXXb5f',
consumerSecret: 'bfceXXXXXXXXXXXXXXXXXa31604ff',
callbackURL: "http://127.0.0.1:1880/auth/strategy/callback",
verify: function(token, tokenSecret, profile, done) {
done(null, profile);
}
},
},
users: [
{ username: "knolleary",permissions: ["*"]}
]
}
};
If you have got:
adminAuth: require("./user-authentication")
in your main settings file, then you don't want to repeat the adminAuth bit in your user auth file. It should be:
module.exports = {
type: "strategy",
...
}
After removing the adminAuth node-red trows a different error
Failed to start server:
TypeError: OAuth2Strategy requires a clientID option
at Strategy.OAuth2Strategy (/home/nemanja/.node-red/node_modules/passport-oauth2/lib/strategy.js:86:34)
at new Strategy (/home/nemanja/.node-red/node_modules/passport-github/lib/strategy.js:62:18)
at Object.genericStrategy (/usr/lib/node_modules/node-red/node_modules/@node-red/editor-api/lib/auth/index.js:175:18)
at Object.init (/usr/lib/node_modules/node-red/node_modules/@node-red/editor-api/lib/index.js:71:22)
at Object.init (/usr/lib/node_modules/node-red/lib/red.js:72:17)
at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:202:9)
at Module._compile (internal/modules/cjs/loader.js:1176:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
at Module.load (internal/modules/cjs/loader.js:1040:32)
at Function.Module._load (internal/modules/cjs/loader.js:929:14)
I am sorry to bother you with this stupid question, but I want to learn how to do it properly.