Skip to content

Commit

Permalink
[Story]: connectors oauth configuration update
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Nagendra committed Feb 14, 2024
1 parent 90c041c commit 8cf86ba
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 23 deletions.
8 changes: 7 additions & 1 deletion pages/api/oauth2/login/facebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ router

let { workspace = '', connector = '', oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_FACEBOOK_CLIENT_ID,
client_secret: process.env.AUTH_FACEBOOK_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_FACEBOOK_CLIENT_ID'],
client_secret: query_response['AUTH_FACEBOOK_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/login/google.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ router

let { workspace = '', connector = '', oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_GOOGLE_CLIENT_ID,
client_secret: process.env.AUTH_GOOGLE_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_GOOGLE_CLIENT_ID'],
client_secret: query_response['AUTH_GOOGLE_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/login/hubspot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ router.use(oauthKeys).get(async (req, res, next) => {

let { workspace = '', connector = '', oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_HUBSPOT_CLIENT_ID,
client_secret: process.env.AUTH_HUBSPOT_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_HUBSPOT_CLIENT_ID'],
client_secret: query_response['AUTH_HUBSPOT_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/login/slack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ router.use(oauthKeys).get(async (req, res, next) => {

let { workspace = '', connector = '', oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_SLACK_CLIENT_ID,
client_secret: process.env.AUTH_SLACK_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_SLACK_CLIENT_ID'],
client_secret: query_response['AUTH_SLACK_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/redirect/facebook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ router

let { oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_FACEBOOK_CLIENT_ID,
client_secret: process.env.AUTH_FACEBOOK_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_FACEBOOK_CLIENT_ID'],
client_secret: query_response['AUTH_FACEBOOK_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/redirect/google.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ router

let { oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_GOOGLE_CLIENT_ID,
client_secret: process.env.AUTH_GOOGLE_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_GOOGLE_CLIENT_ID'],
client_secret: query_response['AUTH_GOOGLE_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/redirect/hubspot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ router

let { oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_HUBSPOT_CLIENT_ID,
client_secret: process.env.AUTH_HUBSPOT_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_HUBSPOT_CLIENT_ID'],
client_secret: query_response['AUTH_HUBSPOT_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
8 changes: 7 additions & 1 deletion pages/api/oauth2/redirect/slack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ router

let { oauth_keys = 'private' } = json;

let credentials = { ...(req.credentials ?? {}) };
let credentials = {};
let query_response = { ...(req.credentials ?? {}) };

if (oauth_keys === 'public') {
credentials = {
client_id: process.env.AUTH_SLACK_CLIENT_ID,
client_secret: process.env.AUTH_SLACK_CLIENT_SECRET
};
} else {
credentials = {
client_id: query_response['AUTH_SLACK_CLIENT_ID'],
client_secret: query_response['AUTH_SLACK_CLIENT_SECRET']
};
}

const query = { ...credentials };
Expand Down
2 changes: 1 addition & 1 deletion pages/spaces/[wid]/connections/create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const ConnectionFlow = () => {
}

// check if authorized
if (hasAuthorizedOAuth(oauth_params)) {
if (hasAuthorizedOAuth(oauth_params, isEditableFlow)) {
setConnectorConfigInConnectionFlow(dispatch, values, connection_flow);
} else {
// update oauth_error in connection flow state
Expand Down
21 changes: 12 additions & 9 deletions src/components/FormInput/FormFieldAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,22 @@ const FormFieldAuth = (props: any) => {
{'Configure'}
</Button>
) : (
hasOAuthAuthorized && (
<Stack sx={{ display: 'flex', flexDirection: 'row' }}>
<IconButton color={'primary'}>
<CustomIcon icon={faCheckCircle} />
</IconButton>
</Stack>
)
)
) : (
hasOAuthAuthorized && (
<Stack sx={{ display: 'flex', flexDirection: 'row' }}>
<Label>{'Configured'}</Label>
<IconButton color={hasOAuthAuthorized ? 'primary' : 'error'}>
<CustomIcon icon={hasOAuthAuthorized ? faCheckCircle : faCircleXmark} />
<IconButton color={'primary'}>
<CustomIcon icon={faCheckCircle} />
</IconButton>
</Stack>
)
) : (
<Stack sx={{ display: 'flex', flexDirection: 'row' }}>
<IconButton color={hasOAuthAuthorized ? 'primary' : 'error'}>
<CustomIcon icon={hasOAuthAuthorized ? faCheckCircle : faCircleXmark} />
</IconButton>
</Stack>
)}
</Stack>
<Item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export const isConnectorRequiresOAuth = (data: any) => {
return false;
};

export const hasAuthorizedOAuth = (oAuthParams: any) => {
return !isObjectEmpty(oAuthParams) ? true : false;
export const hasAuthorizedOAuth = (oAuthParams: any, isEditableFlow: boolean) => {
//TODO: HACK - to check if the user has already authorized based on isEditableFlow
return !isObjectEmpty(oAuthParams) || isEditableFlow ? true : false;
};

const getFieldType = ({ hasOAuth, enumFlag, isSecretKey, type }: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ const ConnectorFormFieldsControl = (props: any) => {

const connection_flow = useSelector((state: RootState) => state.connectionFlow);

const { flowState: { selected_connector = null, oauth_params = {}, oauth_error = '', connector_spec = null } = {} } =
connection_flow;
const {
flowState: {
selected_connector = null,
oauth_params = {},
oauth_error = '',
connector_spec = null,
isEditableFlow = false
} = {}
} = connection_flow;

const workspaceId = useSelector((state: RootState) => state.appFlow.appState.workspaceId);

Expand Down Expand Up @@ -109,7 +116,7 @@ const ConnectorFormFieldsControl = (props: any) => {
{...field}
control={control}
selectedConnector={selected_connector?.display_name ?? ''}
hasAuthorizedOAuth={hasAuthorizedOAuth(oauth_params)}
hasAuthorizedOAuth={hasAuthorizedOAuth(oauth_params, isEditableFlow)}
oauth_error={oauth_error}
onClick={handleOAuthButtonClick}
isConnectorConfigured={isConnectorConfigured({ field, keys })}
Expand Down

0 comments on commit 8cf86ba

Please sign in to comment.