Hi all!
I have a strange scenario where i want to integrate nodered login using oauth2 but only for gmail users and not another google domain.
In the following code, i'm checking if the email address is from gmail and then fill in the empty array that is declared outside the "modules" block.
Then the array is used in the "users" block. But is not working.
// declare the empty users arrays...
let users = [];
module.exports = {
//.....following code....
adminAuth: {
type: "strategy",
strategy: {
name: "google",
label: 'Sign in with Google',
icon: "fa-google",
strategy: require("passport-google-oauth20").Strategy,
options: {
clientID: "xxxxxxxxx",
clientSecret: "xxxxxxxxxxxxx",
callbackURL: "http://localhost:1880/auth/strategy/callback",
scope: ['profile', 'email'],
verify: function (token, tokenSecret, profile, done) {
profile.username = profile.emails.find(x => x.verified).value;
const getUsernameEmail = profile.username;
console.log('Username:', getUsernameEmail);
if (getUsernameEmail.includes('@gmail.com')) {
console.log('The email address is from gmail.com');
}
if (!users.some(user => user.username === getUsernameEmail)) {
users.push({ username: getUsernameEmail, permissions: ["*"] });
}
console.log('Users array:', users);
return done(null, profile)
}
}
},
users: users
The output is:
The email address is from gmail.com
Users array: [ { username: 'lalala@gmail.com', permissions: [ '*' ] } ]
Ok, but i have the following UI message:
What i'm missing here?.
If i hardcode the "users" block like this it works fine.
users: [
{ username: 'lalala@gmail.com', permissions: ["*"] },
{ username: "usuario2@gmail.com", permissions: ["read"] }
]
The main goal is to only allow a certain domain.
Other ideas if how to implement this?.
Thanks a lot!