Skip to content

Commit 7ad99b0

Browse files
committed
Revert "feat(redirectUri): Custom redirect URIs (#408)"
Due to build failures on main This reverts commit 7190340.
1 parent 0d5931e commit 7ad99b0

File tree

13 files changed

+83
-238
lines changed

13 files changed

+83
-238
lines changed

apps/web/app/console/(authenticated)/settings/client.tsx

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,54 @@
22

33
import {toast} from '@openint/ui-v1'
44
import SecureInput from '@openint/ui-v1/components/SecureInput'
5-
import UrlInputForm from '@openint/ui-v1/components/UrlInputForm'
5+
import WebhookInput from '@openint/ui-v1/components/WebhookInput'
66
import {useMutation} from '@openint/ui-v1/trpc'
77
import {useTRPC} from '../client'
88

99
interface SettingsContentProps {
1010
orgId: string
1111
apiKey: string
1212
webhookUrl: string
13-
oauthRedirectUrl: string
1413
}
1514

1615
export function SettingsContent({
1716
orgId,
1817
apiKey,
1918
webhookUrl,
20-
oauthRedirectUrl,
2119
}: SettingsContentProps) {
2220
const trpc = useTRPC()
23-
const setMetadataUrl = useMutation(
24-
trpc.setMetadataUrl.mutationOptions({
21+
const setWebhook = useMutation(
22+
trpc.setWebhookUrl.mutationOptions({
2523
onSuccess: () => {
26-
toast.success('URL saved successfully')
24+
toast.success('Webhook URL saved')
2725
},
2826
onError: (error) => {
2927
toast.error(`Error: ${error.message}`)
3028
},
3129
}),
3230
)
3331

34-
const handleWebhookSave = (value: string) => {
35-
setMetadataUrl.mutate({
36-
urlType: 'webhook_url',
37-
url: value,
38-
})
39-
}
40-
41-
const handleOauthRedirectSave = (value: string) => {
42-
setMetadataUrl.mutate({
43-
urlType: 'oauth_redirect_url',
44-
url: value,
45-
})
32+
const handleSave = (value: string) => {
33+
setWebhook.mutate({webhookUrl: value})
4634
}
4735

4836
return (
4937
<div className="p-6">
5038
<h2 className="mb-4 text-2xl font-bold tracking-tight">Settings</h2>
51-
<SecureInput
52-
label="Organization Id"
53-
value={orgId}
54-
showValue={true}
55-
className="mt-4 flex items-center"
56-
/>
39+
<p className="mb-4 font-bold">
40+
<SecureInput label="Organization Id" value={orgId} showValue={true} />
41+
</p>
5742

58-
<SecureInput
59-
label="API Key"
60-
readOnly
61-
value={apiKey}
62-
className="mt-4 flex items-center"
63-
/>
64-
<UrlInputForm
65-
inputName="Webhook URL"
66-
defaultValue={webhookUrl}
67-
placeholder="https://webhook.site/webhook-url"
68-
onSave={handleWebhookSave}
69-
isSaving={setMetadataUrl.isPending}
70-
className="mt-4 flex items-center"
71-
/>
72-
<UrlInputForm
73-
inputName="OAuth Redirect URL"
74-
defaultValue={oauthRedirectUrl}
75-
placeholder="https://app.example.com/oauth/callback"
76-
onSave={handleOauthRedirectSave}
77-
isSaving={setMetadataUrl.isPending}
78-
className="mt-4 flex items-center"
79-
/>
43+
<div className="mt-4 flex items-center">
44+
<SecureInput label="API Key" readOnly value={apiKey} />
45+
</div>
46+
<div className="mt-4 flex items-center">
47+
<WebhookInput
48+
defaultValue={webhookUrl}
49+
onSave={handleSave}
50+
isSaving={setWebhook.isPending}
51+
/>
52+
</div>
8053
</div>
8154
)
8255
}

apps/web/app/console/(authenticated)/settings/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export default async function SettingsPage(props: PageProps) {
1515
orgId={viewer.orgId ?? ''}
1616
apiKey={org.api_key ?? ''}
1717
webhookUrl={org.metadata?.webhook_url ?? ''}
18-
oauthRedirectUrl={org.metadata?.oauth_redirect_url ?? ''}
1918
/>
2019
</ClientApp>
2120
)

connectors/cnext/_defaults/oauth2/server.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, () => {
115115
{
116116
extCustomerId: `cust_123` as any,
117117
webhookBaseUrl: 'https://example.com/webhook',
118-
orgId: `org_123` as any,
119118
},
120119
{connectionId: 'test_connection_id'},
121120
)
@@ -167,7 +166,6 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, () => {
167166
{
168167
extCustomerId: `cust_123` as any,
169168
webhookBaseUrl: 'https://example.com/webhook',
170-
orgId: `org_123` as any,
171169
},
172170
{connectionId: 'test_connection_id'},
173171
),
@@ -188,7 +186,6 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, () => {
188186
{
189187
extCustomerId: `cust_123` as any,
190188
webhookBaseUrl: 'https://example.com/webhook',
191-
orgId: `org_123` as any,
192189
},
193190
{connectionId: 'test_connection_id'},
194191
),

connectors/cnext/_defaults/oauth2/server.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {z} from 'zod'
22
import type {ConnectorDef, ConnectorServer} from '@openint/cdk'
33
import {extractId, makeId} from '@openint/cdk'
4-
import {getConnectorDefaultCredentials} from '@openint/env'
4+
import {getConnectorDefaultCredentials, getServerUrl} from '@openint/env'
55
import {makeUlid} from '@openint/util'
66
import {oauth2Schemas, zOAuthConfig} from './def'
77
import {
@@ -10,10 +10,7 @@ import {
1010
tokenRefreshHandler,
1111
validateOAuthCredentials,
1212
} from './handlers'
13-
import {
14-
fillOutStringTemplateVariablesInObjectKeys,
15-
getOauthRedirectUri,
16-
} from './utils'
13+
import {fillOutStringTemplateVariablesInObjectKeys} from './utils'
1714

1815
function injectCcfgDefaultCredentials(
1916
connectorConfig: z.infer<typeof oauth2Schemas.connectorConfig>,
@@ -124,7 +121,7 @@ export function generateOAuth2Server<
124121
),
125122
connector_config: ccfg,
126123
},
127-
redirectUri: await getOauthRedirectUri(connectionSettings.orgId),
124+
redirectUri: getServerUrl(null) + '/connect/callback',
128125
connectionId: connectionId,
129126
// QQ: fix issue with Type '{ authorization_url: string; }' is not assignable to type 'T["_types"]["connectInput"]
130127
}) as any
@@ -151,7 +148,7 @@ export function generateOAuth2Server<
151148
} satisfies z.infer<typeof zOAuthConfig>,
152149
code: connectOutput.code,
153150
state: connectOutput.state,
154-
redirectUri: await getOauthRedirectUri(connectionSettings.orgId),
151+
redirectUri: getServerUrl(null) + '/connect/callback',
155152
})
156153

157154
return {

connectors/cnext/_defaults/oauth2/utils.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import {z} from 'zod'
2-
import {eq, schema} from '@openint/db'
3-
import {initDbNeon} from '@openint/db/db.neon'
4-
import {envRequired, getServerUrl} from '@openint/env'
52
import {zOAuthConfig} from './def'
63

74
export function prepareScopes(
@@ -145,25 +142,3 @@ export function mapOauthParams(
145142

146143
return result
147144
}
148-
149-
export async function getOauthRedirectUri(
150-
orgId: string,
151-
organization?: {metadata: {oauth_redirect_url?: string}},
152-
): Promise<string> {
153-
// if organization is provided, use the oauth_redirect_url from the organization
154-
if (organization) {
155-
return (
156-
organization.metadata?.oauth_redirect_url ??
157-
getServerUrl(null) + '/connect/callback'
158-
)
159-
}
160-
// if no organization is provided, get the organization from the database
161-
const db = initDbNeon(envRequired.DATABASE_URL)
162-
const org = await db.query.organization.findFirst({
163-
where: eq(schema.organization.id, orgId),
164-
})
165-
if (!org) {
166-
throw new Error(`Organization not found: ${orgId}`)
167-
}
168-
return org.metadata?.oauth_redirect_url ?? getServerUrl(null) + '/connect/callback'
169-
}

kits/cdk/connector-meta.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ export interface ConnectContext<TSettings>
113113
externalId: ExternalId
114114
settings: TSettings
115115
} | null
116-
orgId: `org_${string}`
117116
}
118117

119118
// TODO: We should rename `provider` to `integration` given that they are both

packages/api-v1/routers/connect.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export const connectRouter = router({
103103
extCustomerId: (ctx.viewer.role === 'customer'
104104
? ctx.viewer.customerId
105105
: ctx.viewer.userId) as ExtCustomerId,
106-
orgId: ctx.viewer.orgId,
107106
},
108107
input.data.input,
109108
)
@@ -171,12 +170,6 @@ export const connectRouter = router({
171170
})
172171
}
173172

174-
if (!ctx.viewer.orgId) {
175-
throw new TRPCError({
176-
code: 'BAD_REQUEST',
177-
message: 'OrgId is required',
178-
})
179-
}
180173
console.log('preConnect', input, ctx, ccfg)
181174
const connUpdate = await connector.postConnect?.(
182175
input.data.input,
@@ -187,7 +180,6 @@ export const connectRouter = router({
187180
extCustomerId: (ctx.viewer.role === 'customer'
188181
? ctx.viewer.customerId
189182
: ctx.viewer.userId) as ExtCustomerId,
190-
orgId: ctx.viewer.orgId,
191183
},
192184
)
193185
const id = makeId('conn', input.data.connector_name, makeUlid())

packages/api-v1/routers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {connectorConfigRouter} from './connectorConfig'
77
import {customerRouter} from './customer'
88
import {eventRouter} from './event'
99
import {generalRouter} from './general'
10-
import {organizationRouter} from './organization'
10+
import {onboardingRouter} from './onboarding'
1111

1212
export const appRouter = trpc.mergeRouters(
1313
connectorRouter,
@@ -17,7 +17,7 @@ export const appRouter = trpc.mergeRouters(
1717
eventRouter,
1818
customerRouter,
1919
generalRouter,
20-
organizationRouter,
20+
onboardingRouter,
2121
)
2222

2323
export type AppRouter = typeof appRouter

packages/api-v1/routers/organization.spec.ts renamed to packages/api-v1/routers/onboarding.spec.ts

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import type {Viewer} from '@openint/cdk'
2-
import {eq, schema} from '@openint/db'
2+
import {schema} from '@openint/db'
33
import {describeEachDatabase} from '@openint/db/__tests__/test-utils'
44
import {routerContextFromViewer} from '../trpc/context'
5-
import {organizationRouter} from './organization'
5+
import {onboardingRouter} from './onboarding'
66

77
const logger = false
88

99
describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, (db) => {
1010
function getCaller(viewer: Viewer) {
11-
return organizationRouter.createCaller(
12-
routerContextFromViewer({db, viewer}),
13-
)
11+
return onboardingRouter.createCaller(routerContextFromViewer({db, viewer}))
1412
}
1513

1614
const orgId = 'org_222'
@@ -103,69 +101,14 @@ describeEachDatabase({drivers: ['pglite'], migrate: true, logger}, (db) => {
103101
})
104102
})
105103

106-
describe('setMetadataUrl', () => {
104+
describe('setWebhookUrl', () => {
107105
test('updates webhook URL', async () => {
108-
await asOrg.setMetadataUrl({
109-
urlType: 'webhook_url',
110-
url: 'https://webhook.site/webhook-url',
106+
await asOrg.setWebhookUrl({
107+
webhookUrl: 'https://webhook.site/xxx',
111108
})
112109

113110
const org = await asOrg.getOrganization()
114-
expect(org.metadata.webhook_url).toBe('https://webhook.site/webhook-url')
115-
})
116-
117-
test('updates OAuth redirect URL', async () => {
118-
await asOrg.setMetadataUrl({
119-
urlType: 'oauth_redirect_url',
120-
url: 'https://app.example.com/oauth/callback',
121-
})
122-
123-
const org = await db.query.organization.findFirst({
124-
where: eq(schema.organization.id, orgId),
125-
})
126-
expect(org?.metadata?.oauth_redirect_url).toBe(
127-
'https://app.example.com/oauth/callback',
128-
)
129-
})
130-
131-
test('rejects invalid webhook URL', async () => {
132-
await expect(
133-
asOrg.setMetadataUrl({
134-
urlType: 'webhook_url',
135-
url: 'http://insecure-webhook.com',
136-
}),
137-
).rejects.toThrow('Invalid webhook URL. It must start with "https://".')
138-
})
139-
140-
test('rejects invalid OAuth redirect URL', async () => {
141-
await expect(
142-
asOrg.setMetadataUrl({
143-
urlType: 'oauth_redirect_url',
144-
url: 'not-a-valid-url',
145-
}),
146-
).rejects.toThrow(
147-
'Invalid OAuth redirect URL. Please provide a valid URL.',
148-
)
149-
})
150-
151-
test('does not update if URL is unchanged', async () => {
152-
const initialOrg = await db.query.organization.findFirst({
153-
where: eq(schema.organization.id, orgId),
154-
})
155-
156-
// Wait a bit to ensure timestamp would be different if updated
157-
await new Promise((resolve) => setTimeout(resolve, 5))
158-
159-
await asOrg.setMetadataUrl({
160-
urlType: 'webhook_url',
161-
url: 'https://webhook.site/webhook-url',
162-
})
163-
164-
const updatedOrg = await db.query.organization.findFirst({
165-
where: eq(schema.organization.id, orgId),
166-
})
167-
168-
expect(updatedOrg?.metadata).toEqual(initialOrg?.metadata)
111+
expect(org.metadata.webhook_url).toBe('https://webhook.site/xxx')
169112
})
170113
})
171114
})

0 commit comments

Comments
 (0)