diff --git a/packages/auth/src/index.js b/packages/auth/src/index.js index 4ef30c9f02..d1b09c3ae0 100644 --- a/packages/auth/src/index.js +++ b/packages/auth/src/index.js @@ -1,7 +1,6 @@ const passport = require("koa-passport") const LocalStrategy = require("passport-local").Strategy const JwtStrategy = require("passport-jwt").Strategy -const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy const database = require("./db") const { StaticDatabases, DocumentTypes } = require("./db/utils") const { jwt, local, google, authenticated } = require("./middleware") @@ -27,7 +26,7 @@ const { // Strategies passport.use(new LocalStrategy(local.options, local.authenticate)) passport.use(new JwtStrategy(jwt.options, jwt.authenticate)) -passport.use(new GoogleStrategy(google.options, google.authenticate)) +// passport.use(new GoogleStrategy(google.options, google.authenticate)) passport.serializeUser((user, done) => done(null, user)) diff --git a/packages/auth/src/middleware/passport/google.js b/packages/auth/src/middleware/passport/google.js index 9113fba1cf..69c038638f 100644 --- a/packages/auth/src/middleware/passport/google.js +++ b/packages/auth/src/middleware/passport/google.js @@ -1,6 +1,7 @@ const env = require("../../environment") const jwt = require("jsonwebtoken") const database = require("../../db") +const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy const { StaticDatabases, generateUserID } = require("../../db/utils") exports.options = { @@ -9,7 +10,7 @@ exports.options = { callbackURL: env.GOOGLE_AUTH_CALLBACK_URL, } -exports.authenticate = async function(token, tokenSecret, profile, done) { +async function authenticate(token, tokenSecret, profile, done) { if (!profile._json.email) return done(null, false, "Email Required.") // Check the user exists in the instance DB by email @@ -52,3 +53,14 @@ exports.authenticate = async function(token, tokenSecret, profile, done) { return done(null, dbUser) } + +exports.CustomGoogleStrategy = function(config) { + return new GoogleStrategy( + { + clientID: config.clientID, + clientSecret: config.clientSecret, + callbackURL: config.callbackURL, + }, + authenticate + ) +} diff --git a/packages/worker/.vscode/launch.json b/packages/worker/.vscode/launch.json new file mode 100644 index 0000000000..7417938376 --- /dev/null +++ b/packages/worker/.vscode/launch.json @@ -0,0 +1,139 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Start Server", + "program": "${workspaceFolder}/src/index.js" + }, + { + "type": "node", + "request": "launch", + "name": "Jest - All", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": [], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Users", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["user.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Instances", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["instance.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Roles", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["role.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Records", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["record.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Models", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["table.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Views", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["view.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest - Applications", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["application.spec", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Jest Builder", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["builder", "--runInBand"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "disableOptimisticBPs": true, + "windows": { + "program": "${workspaceFolder}/node_modules/jest-cli/bin/jest", + } + }, + { + "type": "node", + "request": "launch", + "name": "Initialise Budibase", + "program": "yarn", + "args": ["run", "initialise"], + "console": "externalTerminal" + } + ] +} diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index 10f1d2cf2b..c28f0179ee 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -69,6 +69,13 @@ exports.fetch = async function(ctx) { exports.find = async function(ctx) { const db = new CouchDB(GLOBAL_DB) + const response = await db.allDocs( + getConfigParams(undefined, { + include_docs: true, + }) + ) + const groups = response.rows.map(row => row.doc) + ctx.body = groups try { const record = await db.get(ctx.params.id) ctx.body = record diff --git a/packages/worker/src/api/controllers/auth.js b/packages/worker/src/api/controllers/auth.js index d2aaf552e0..df759ffc84 100644 --- a/packages/worker/src/api/controllers/auth.js +++ b/packages/worker/src/api/controllers/auth.js @@ -65,6 +65,14 @@ exports.logout = async ctx => { ctx.body = { message: "User logged out" } } +// exports.googleAuth = async (ctx, next) => +// passport.authenticate( +// "google", +// { successRedirect: "/", failureRedirect: "/" }, +// (ctx +// setToken(ctx, next) +// ) + exports.googleAuth = async (ctx, next) => { return passport.authenticate( "google",