diff --git a/pages/api/oauth2/login/facebook.tsx b/pages/api/oauth2/login/facebook.tsx index e6609ee7..b849c3e4 100644 --- a/pages/api/oauth2/login/facebook.tsx +++ b/pages/api/oauth2/login/facebook.tsx @@ -11,14 +11,20 @@ import passport from 'passport'; import { Strategy as FacebookStrategy } from 'passport-facebook'; import { oauthKeys } from '@/lib/oauth_middleware'; -export const createStrategy = ({ client_id = '', client_secret = '', workspace = '', connector = '' }) => { +export const createStrategy = ({ + client_id = '', + client_secret = '', + workspace = '', + connector = '', + oauth_keys = 'private' +}) => { const strategy = new FacebookStrategy( { clientID: client_id as string, clientSecret: client_secret as string, authType: 'reauthenticate', profileFields: ['id', 'displayName', 'photos', 'email'], - callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/facebook?workspace=${workspace}&connector=${connector}` // this is the endpoint you registered on hubspot while creating your app. This endpoint would exist on your application for verifying the authentication + callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/facebook?workspace=${workspace}&connector=${connector}&oauth_keys=${oauth_keys}` // this is the endpoint you registered on hubspot while creating your app. This endpoint would exist on your application for verifying the authentication }, async (_accessToken, _refreshToken, profile: any, cb: any) => { try { @@ -40,8 +46,18 @@ router .use(oauthKeys) .get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_FACEBOOK_CLIENT_ID, + client_secret: process.env.AUTH_FACEBOOK_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; const strategy = createStrategy(query); return passport.authenticate(strategy, { diff --git a/pages/api/oauth2/login/google.tsx b/pages/api/oauth2/login/google.tsx index 2c27dfcb..b5c2539c 100644 --- a/pages/api/oauth2/login/google.tsx +++ b/pages/api/oauth2/login/google.tsx @@ -20,12 +20,18 @@ const saveUser = (user: Profile) => { }); }; -export const createStrategy = ({ client_id = '', client_secret = '', workspace = '', connector = '' }) => { +export const createStrategy = ({ + client_id = '', + client_secret = '', + workspace = '', + connector = '', + oauth_keys = 'private' +}) => { const strategy = new GoogleStrategy( { clientID: client_id as string, clientSecret: client_secret as string, - callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/google?workspace=${workspace}&connector=${connector}` // this is the endpoint you registered on hubspot while creating your app. This endpoint would exist on your application for verifying the authentication + callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/google?workspace=${workspace}&connector=${connector}&oauth_keys=${oauth_keys}` // this is the endpoint you registered on hubspot while creating your app. This endpoint would exist on your application for verifying the authentication }, async (_accessToken, _refreshToken, profile: any, cb: any) => { try { @@ -48,8 +54,19 @@ router .use(oauthKeys) .get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_GOOGLE_CLIENT_ID, + client_secret: process.env.AUTH_GOOGLE_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; + const strategy = createStrategy(query); return passport.authenticate(strategy, { diff --git a/pages/api/oauth2/login/hubspot.tsx b/pages/api/oauth2/login/hubspot.tsx index a77edf86..1f9f326d 100644 --- a/pages/api/oauth2/login/hubspot.tsx +++ b/pages/api/oauth2/login/hubspot.tsx @@ -19,13 +19,19 @@ const saveUser = (user: Profile) => { }); }; -export const createStrategy = ({ client_id = '', client_secret = '', workspace = '', connector = '' }) => { +export const createStrategy = ({ + client_id = '', + client_secret = '', + workspace = '', + connector = '', + oauth_keys = 'private' +}) => { const strategy = new HubspotStrategy( { clientID: client_id as string, clientSecret: client_secret as string, user_scope: ['identity.basic', 'identity.email'], - callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/hubspot?workspace=${workspace}&connector=${connector}`, // this is the endpoint you registered on hubspot while creating your app. This endpoint would exist on your application for verifying the authentication + callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/hubspot?workspace=${workspace}&connector=${connector}&oauth_keys=${oauth_keys}`, // this is the endpoint you registered on hubspot while creating your app. This endpoint would exist on your application for verifying the authentication passReqToCallback: true }, async (req, _accessToken, _refreshToken, profile, cb: any) => { @@ -46,8 +52,19 @@ export const createStrategy = ({ client_id = '', client_secret = '', workspace = const router = createRouter(); router.use(oauthKeys).get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_HUBSPOT_CLIENT_ID, + client_secret: process.env.AUTH_HUBSPOT_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; + const strategy = createStrategy(query); return passport.authenticate(strategy, { diff --git a/pages/api/oauth2/login/slack.tsx b/pages/api/oauth2/login/slack.tsx index b5565cec..08d46a7b 100644 --- a/pages/api/oauth2/login/slack.tsx +++ b/pages/api/oauth2/login/slack.tsx @@ -19,14 +19,20 @@ const saveUser = (user) => { }); }; -export const createStrategy = ({ client_id = '', client_secret = '', workspace = '', connector = '' }) => { +export const createStrategy = ({ + client_id = '', + client_secret = '', + workspace = '', + connector = '', + oauth_keys = 'private' +}) => { const strategy = new SlackStrategy( { clientID: client_id as string, clientSecret: client_secret as string, user_scope: ['identity.basic', 'identity.email'], scope: ['users.profile:read', 'chat:write', 'channels:read', 'channels:join'], // default, - callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/slack?workspace=${workspace}&connector=${connector}` + callbackURL: `${process.env.WEB_URL}/api/oauth2/redirect/slack?workspace=${workspace}&connector=${connector}&oauth_keys=${oauth_keys}` }, async (accessToken, params, profile, cb: any) => { try { @@ -47,8 +53,18 @@ export const createStrategy = ({ client_id = '', client_secret = '', workspace = const router = createRouter(); router.use(oauthKeys).get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_SLACK_CLIENT_ID, + client_secret: process.env.AUTH_SLACK_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; const strategy = createStrategy(query); return passport.authenticate(strategy, null, { diff --git a/pages/api/oauth2/redirect/facebook.tsx b/pages/api/oauth2/redirect/facebook.tsx index 617f30b0..73f34f05 100644 --- a/pages/api/oauth2/redirect/facebook.tsx +++ b/pages/api/oauth2/redirect/facebook.tsx @@ -17,8 +17,19 @@ router .use(oauthKeys) .get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_FACEBOOK_CLIENT_ID, + client_secret: process.env.AUTH_FACEBOOK_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; + const strategy = createStrategy(query); return passport.authenticate(strategy, { session: 'false' }, async (err: any, user: any) => { diff --git a/pages/api/oauth2/redirect/google.tsx b/pages/api/oauth2/redirect/google.tsx index db746782..c0c5cc43 100644 --- a/pages/api/oauth2/redirect/google.tsx +++ b/pages/api/oauth2/redirect/google.tsx @@ -17,8 +17,19 @@ router .use(oauthKeys) .get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_GOOGLE_CLIENT_ID, + client_secret: process.env.AUTH_GOOGLE_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; + const strategy = createStrategy(query); return passport.authenticate(strategy, { session: 'false' }, async (err: any, user: any) => { diff --git a/pages/api/oauth2/redirect/hubspot.ts b/pages/api/oauth2/redirect/hubspot.ts index 04c548eb..b3f25354 100644 --- a/pages/api/oauth2/redirect/hubspot.ts +++ b/pages/api/oauth2/redirect/hubspot.ts @@ -17,8 +17,18 @@ router .use(oauthKeys) .get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_HUBSPOT_CLIENT_ID, + client_secret: process.env.AUTH_HUBSPOT_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; const strategy = createStrategy(query); return passport.authenticate(strategy, { session: 'false' }, async (err: any, user: any) => { diff --git a/pages/api/oauth2/redirect/slack.tsx b/pages/api/oauth2/redirect/slack.tsx index e5596a6d..86850996 100644 --- a/pages/api/oauth2/redirect/slack.tsx +++ b/pages/api/oauth2/redirect/slack.tsx @@ -17,8 +17,18 @@ router .use(oauthKeys) .get(async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; - const query = { ...req.credentials, workspace: workspace, connector }; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + let credentials = { ...(req.credentials ?? {}) }; + + if (oauth_keys === 'public') { + credentials = { + client_id: process.env.AUTH_SLACK_CLIENT_ID, + client_secret: process.env.AUTH_SLACK_CLIENT_SECRET + }; + } + + const query = { ...credentials, workspace: workspace, connector: connector, oauth_keys: oauth_keys }; const strategy = createStrategy(query); return passport.authenticate(strategy, { session: 'false' }, async (err: any, user: any) => { @@ -26,12 +36,12 @@ router provider: user?.provider ?? 'slack', access_token: user?.['_accessToken'] ?? '', refresh_token: user?._refreshToken ?? '', - id: user.profile.email, - unique_id: user.profile.email, + id: user?.profile?.email ?? '', + unique_id: user?.profile?.email ?? '', bot_user_id: user?.['_bot_user_id'] ?? '', - email: user.profile.email, - name: user.profile.real_name, - image: user.profile.image_original + email: user?.profile?.email ?? '', + name: user?.profile?.real_name ?? '', + image: user?.profile?.image_original ?? '' }); res.redirect('/auth/callback?' + params.toString()); diff --git a/pages/auth/callback/index.tsx b/pages/auth/callback/index.tsx index 500765bd..828ac58e 100644 --- a/pages/auth/callback/index.tsx +++ b/pages/auth/callback/index.tsx @@ -23,9 +23,7 @@ const OAuthRedirectPage = () => { const dispatch = useDispatch(); /** Redux store */ - const connection_flow = useSelector( - (state: RootState) => state.connectionFlow - ); + const connection_flow = useSelector((state: RootState) => state.connectionFlow); const { flowState: {} = {} } = connection_flow; const appState = useSelector((state: RootState) => state.appFlow.appState); @@ -109,6 +107,7 @@ const OAuthRedirectPage = () => { export const getOAuthParams = (params: any) => { const oAuthParams = params || {}; + const { provider = '' } = oAuthParams; switch (provider) { case 'facebook': diff --git a/pages/spaces/[wid]/connections/destinations/index.tsx b/pages/spaces/[wid]/connections/destinations/index.tsx index 54e217e4..f9320668 100644 --- a/pages/spaces/[wid]/connections/destinations/index.tsx +++ b/pages/spaces/[wid]/connections/destinations/index.tsx @@ -15,11 +15,7 @@ import { NextPageWithLayout } from '@/pages_app'; import SidebarLayout from '@layouts/SidebarLayout'; -import { - ConnectionType, - ConnectionsPageTitle, - CreateConnectionTitle -} from '@content/Connections/ConnectionModel'; +import { ConnectionType, ConnectionsPageTitle, CreateConnectionTitle } from '@content/Connections/ConnectionModel'; import Connections from '@content/Connections'; import constants from '@constants/index'; diff --git a/pages/spaces/[wid]/connections/warehouses/index.tsx b/pages/spaces/[wid]/connections/warehouses/index.tsx index 43fd9826..d7247435 100644 --- a/pages/spaces/[wid]/connections/warehouses/index.tsx +++ b/pages/spaces/[wid]/connections/warehouses/index.tsx @@ -15,11 +15,7 @@ import { NextPageWithLayout } from '@/pages_app'; import SidebarLayout from '@layouts/SidebarLayout'; -import { - ConnectionType, - ConnectionsPageTitle, - CreateConnectionTitle -} from '@content/Connections/ConnectionModel'; +import { ConnectionType, ConnectionsPageTitle, CreateConnectionTitle } from '@content/Connections/ConnectionModel'; import Connections from '@content/Connections'; import constants from '@constants/index'; diff --git a/src/components/FormInput/FormField.tsx b/src/components/FormInput/FormField.tsx index 82e61c36..2e7570db 100644 --- a/src/components/FormInput/FormField.tsx +++ b/src/components/FormInput/FormField.tsx @@ -17,6 +17,7 @@ interface FormFieldProps extends FormObject { oauth_error?: string; control: any; isConnectorConfigured?: boolean; + isConfigurationRequired?: boolean; handleOnConfigureButtonClick: (data: any) => void; } @@ -33,6 +34,7 @@ const FormField = ({ selectedConnector, onClick, isConnectorConfigured, + isConfigurationRequired, handleOnConfigureButtonClick, hasAuthorizedOAuth, oauth_error, @@ -60,6 +62,7 @@ const FormField = ({ label={label} onClick={onClick} isConnectorConfigured={isConnectorConfigured} + isConfigurationRequired={isConfigurationRequired} handleOnConfigureButtonClick={handleOnConfigureButtonClick} oAuthProvider={oAuthProvider} oauth_error={oauth_error} diff --git a/src/components/FormInput/FormFieldAuth.tsx b/src/components/FormInput/FormFieldAuth.tsx index 3db5b59b..f345ec80 100644 --- a/src/components/FormInput/FormFieldAuth.tsx +++ b/src/components/FormInput/FormFieldAuth.tsx @@ -4,7 +4,7 @@ * Author: Nagendra S @ valmi.io */ -import { Box, Button, IconButton, InputLabel, Stack, Typography, styled } from '@mui/material'; +import { Box, Button, IconButton, InputLabel, Stack, Tooltip, Typography, styled } from '@mui/material'; import { getOauthColorCode, @@ -48,6 +48,7 @@ const FormFieldAuth = (props: any) => { hasOAuthAuthorized, oauth_error = '', isConnectorConfigured, + isConfigurationRequired, handleOnConfigureButtonClick } = props; @@ -55,86 +56,98 @@ const FormFieldAuth = (props: any) => { <> - {!isConnectorConfigured ? ( - - ) : ( - - - - - - - )} + {isConfigurationRequired ? ( + !isConnectorConfigured ? ( + + ) : ( + + + + + + + ) + ) : null} - isConnectorConfigured && onClick({ oAuthProvider: getOAuthProvider(oAuthProvider) })} - > - {getOAuthProvider(oAuthProvider) === 'google' ? ( - - {' '} + + { + if (!isConfigurationRequired) { + onClick({ oAuthProvider: getOAuthProvider(oAuthProvider) }); + } else if (isConnectorConfigured) { + onClick({ oAuthProvider: getOAuthProvider(oAuthProvider) }); + } + return null; + }} + > + {getOAuthProvider(oAuthProvider) === 'google' ? ( + + {' '} + {' '} + + ) : ( {' '} - - ) : ( - + )} + + + {' '} + {getOauthLoginText({ oAuth: getOAuthProvider(oAuthProvider) })} - /> - )} - - - {' '} - {getOauthLoginText({ - oAuth: getOAuthProvider(oAuthProvider) - })} - - + + + diff --git a/src/components/PageTitle/index.tsx b/src/components/PageTitle/index.tsx index 5d3cadd3..0f62ca14 100644 --- a/src/components/PageTitle/index.tsx +++ b/src/components/PageTitle/index.tsx @@ -36,12 +36,7 @@ const PageTitle: FC = ({ let endIcon = null; let startIcon = null; startIcon = displayStartIcon && ; - endIcon = isFetching && ( - theme.colors.alpha.white[100] }} - /> - ); + endIcon = isFetching && theme.colors.alpha.white[100] }} />; return ( = ({ {displayButton && ( {link ? ( - + diff --git a/src/lib/oauth_middleware/index.tsx b/src/lib/oauth_middleware/index.tsx index cd4b45a1..59371e09 100644 --- a/src/lib/oauth_middleware/index.tsx +++ b/src/lib/oauth_middleware/index.tsx @@ -9,7 +9,11 @@ import { getAccessTokenCookie, getBaseUrl } from '@/pagesapi/utils'; import axios from 'axios'; export const oauthKeys = async (req, res, next) => { - let { workspace = '', connector = '' } = req.query; + let { workspace = '', connector = '', oauth_keys = 'private' } = req.query; + + if (oauth_keys === 'public') { + return next(); + } let url = `${getBaseUrl()}/oauth/workspaces/${workspace}/keys/${connector}`;