|
|
|
@ -1,15 +1,37 @@ |
|
|
|
const google = require("../google") |
|
|
|
const { Cookies } = require("../../../constants") |
|
|
|
const { Cookies, Configs } = require("../../../constants") |
|
|
|
const { clearCookie, getCookie } = require("../../../utils") |
|
|
|
const { getDB } = require("../../../db") |
|
|
|
const { getScopedConfig } = require("../../../db/utils") |
|
|
|
const environment = require("../../../environment") |
|
|
|
const { getGlobalDB } = require("../../../tenancy") |
|
|
|
|
|
|
|
async function fetchGoogleCreds() { |
|
|
|
let config |
|
|
|
|
|
|
|
// try and get the config from the tenant
|
|
|
|
const db = getGlobalDB() |
|
|
|
const googleConfig = await getScopedConfig(db, { |
|
|
|
type: Configs.GOOGLE, |
|
|
|
}) |
|
|
|
if (googleConfig.clientID && googleConfig.clientSecret) { |
|
|
|
config = googleConfig |
|
|
|
} |
|
|
|
|
|
|
|
// fall back to env variables
|
|
|
|
if (!config) { |
|
|
|
config = { |
|
|
|
clientID: environment.GOOGLE_CLIENT_ID, |
|
|
|
clientSecret: environment.GOOGLE_CLIENT_SECRET, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return googleConfig |
|
|
|
} |
|
|
|
|
|
|
|
async function preAuth(passport, ctx, next) { |
|
|
|
// get the relevant config
|
|
|
|
const googleConfig = { |
|
|
|
clientID: environment.GOOGLE_CLIENT_ID, |
|
|
|
clientSecret: environment.GOOGLE_CLIENT_SECRET, |
|
|
|
} |
|
|
|
const googleConfig = await fetchGoogleCreds() |
|
|
|
let callbackUrl = `${environment.PLATFORM_URL}/api/global/auth/datasource/google/callback` |
|
|
|
const strategy = await google.strategyFactory(googleConfig, callbackUrl) |
|
|
|
|
|
|
|
@ -26,10 +48,7 @@ async function preAuth(passport, ctx, next) { |
|
|
|
|
|
|
|
async function postAuth(passport, ctx, next) { |
|
|
|
// get the relevant config
|
|
|
|
const config = { |
|
|
|
clientID: environment.GOOGLE_CLIENT_ID, |
|
|
|
clientSecret: environment.GOOGLE_CLIENT_SECRET, |
|
|
|
} |
|
|
|
const config = await fetchGoogleCreds() |
|
|
|
|
|
|
|
let callbackUrl = `${environment.PLATFORM_URL}/api/global/auth/datasource/google/callback` |
|
|
|
const strategy = await google.strategyFactory( |
|
|
|
|