Skip to content

Commit

Permalink
supporting custom redirects for customers (#257)
Browse files Browse the repository at this point in the history
* supporting custom redirects for customers

* fix spreading

* checking viewer

* moving to backend preconnect
  • Loading branch information
pellicceama authored Feb 13, 2025
1 parent 0cb5287 commit ef9b5bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
15 changes: 14 additions & 1 deletion connectors/connector-google/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const googleServer = {
// body: JSON.stringify(input.body),
// }),
// eslint-disable-next-line @typescript-eslint/require-await
async preConnect(_, context) {
async preConnect(_, context, config) {
// This returns auth options for Nango connect because it is an oauth integration
// this behavior is not type checked though and could use some improvement
// May be fixed if we turn nango into a connector
Expand All @@ -110,6 +110,18 @@ export const googleServer = {
{} as Record<string, string | undefined>,
)

const orgId = (config as any).orgId

if (!orgId) {
throw new Error('orgId is required in preconnect() config param')
}

const redirect_uri =
orgId === 'org_2n4lEDaqfBgyEtFmbsDnFFppAR5' ||
orgId === 'org_2n4lU7bvAbbAOqVSHhCNKCAYmft'
? 'https://agents.doubleo.ai/connect/callback'
: undefined

if (
context.integrationExternalId &&
context.integrationExternalId in integrationScopesMap
Expand All @@ -122,6 +134,7 @@ export const googleServer = {
context.integrationExternalId as keyof typeof integrationScopesMap
],
),
...(redirect_uri ? {redirect_uri} : {}),
},
}
console.log('[googleServer] authParams', authParams)
Expand Down
19 changes: 8 additions & 11 deletions kits/cdk/internal/oauthConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,20 @@ export function oauthConnect({
connection_params?: Record<string, string>
}
}): Promise<OauthBaseTypes['connectOutput']> {
// console.log('oauthConnect', {
// connectorName,
// connectorConfigId,
// connectionId,
// authOptions,
// })
return nangoFrontend
.auth(
connectorConfigId,
connectionId ?? makeId('conn', connectorName, makeUlid()),
{
params: {...authOptions?.connection_params},
...authOptions,
// authOptions would tend to contain the authorization_params needed to make the initial connection
// authorization_params: {
// scope: 'https://www.googleapis.com/auth/drive.readonly',
// },
params: {
...authOptions?.connection_params,
},
authorization_params: {
...authOptions?.authorization_params,
// note: we can in future make this dependant ont he host if not passed by authorization_params
// ...(redirect_uri ? {redirect_uri} : {}),
},
},
)
.then((r) => oauthBaseSchema.connectOutput.parse(r))
Expand Down
11 changes: 10 additions & 1 deletion packages/engine-frontend/hocs/WithConnectorConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
useToast,
} from '@openint/ui'
import {z} from '@openint/util'
import {useViewerContext} from '@/components/viewer-context'
import {
useOpenIntConnectContext,
useOptionalOpenIntConnectContext,
Expand Down Expand Up @@ -63,6 +64,7 @@ export const WithConnectorConnect = ({
}) => React.ReactNode
}) => {
// console.log('WithConnectorConnect', int.id, int.connector)
const {viewer} = useViewerContext()
const {clientConnectors} = useOpenIntConnectContext()
// TODO: Restore connectFnMap so that we respect the rules of hooks to always render all hooks
// and not skip rendering or conditionally rendering hooks
Expand Down Expand Up @@ -108,9 +110,16 @@ export const WithConnectorConnect = ({
? extractId(integration.id)[2]
: undefined

if (!viewer || !viewer.orgId) {
throw new Error('Missing orgId')
}
// TODO: Handle preConnectInput schema and such... for example for Plaid
const preConnect = _trpcReact.preConnect.useQuery(
[ccfg.id, {connectionExternalId, integrationExternalId}, {}],
[
ccfg.id,
{connectionExternalId, integrationExternalId},
{orgId: viewer?.orgId},
],
// note: this used to be enabled: ccfg.connector.hasPreConnect
// but we disabled it as it made too many calls for plaid and just left
// it as a noop to be lazy called by the refetch below
Expand Down

0 comments on commit ef9b5bd

Please sign in to comment.