Skip to content

Commit

Permalink
feat(UI-1260): add custom OAuth GitHub connection
Browse files Browse the repository at this point in the history
  • Loading branch information
J1za committed Jan 28, 2025
1 parent 54b05f4 commit e2ba68d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const GithubIntegrationAddForm = ({
await handleOAuth(connectionId, Integrations.github);
break;
case ConnectionAuthType.CustomOAuth:
await handleCustomOauth(connectionId, Integrations.github);
await handleCustomOauth(connectionId, Integrations.github, ConnectionAuthType.CustomOAuth);
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const integrationDataKeys = {
auth0: ["cid", "client_id", "client_secret", "auth0_domain"],
google: ["auth_scopes", "cal_id", "form_id"],
github: ["client_id", "client_secret", "app_id", "webhook_secret", "enterprise_url", "private_key"],
};
14 changes: 11 additions & 3 deletions src/hooks/useConnectionForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,16 @@ export const useConnectionForm = (validationSchema: ZodObject<ZodRawShape>, mode
}
};

const handleCustomOauth = async (oauthConnectionId: string, integrationName: string) => {
const handleCustomOauth = async (
oauthConnectionId: string,
integrationName: keyof typeof Integrations | typeof defaultGoogleConnectionName,
authType?: ConnectionAuthType.CustomOAuth | ConnectionAuthType.Oauth
) => {
setIsLoading(true);
try {
await VariablesService.setByConnectiontId(oauthConnectionId, {
name: "auth_type",
value: ConnectionAuthType.Oauth,
value: authType || ConnectionAuthType.Oauth,
isSecret: false,
scopeId: oauthConnectionId,
});
Expand All @@ -377,9 +381,13 @@ export const useConnectionForm = (validationSchema: ZodObject<ZodRawShape>, mode
connectionData,
integrationDataKeys[integrationName.toString() as keyof typeof integrationDataKeys]
);
const intCustomOAuthUrl: Partial<Record<Integrations | typeof defaultGoogleConnectionName, string>> = {
[Integrations.github]: "custom-oauth",
[Integrations.auth0]: "save",
};

openPopup(
`${apiBaseUrl}/${integrationName}/save?cid=${oauthConnectionId}&origin=web&auth_type=oauth&${urlParams}`,
`${apiBaseUrl}/${integrationName}/${intCustomOAuthUrl[integrationName]}?cid=${oauthConnectionId}&origin=web&auth_type=oauth&${urlParams}`,
"Authorize"
);
startCheckingStatus(oauthConnectionId);
Expand Down

0 comments on commit e2ba68d

Please sign in to comment.