From 6b1dff65be6d1d55f6ed6b58999a2fbef03fd094 Mon Sep 17 00:00:00 2001 From: Bill Leoutsakos Date: Thu, 3 Sep 2026 09:40:53 -0700 Subject: [PATCH 1/2] fix(monday): forward users through app installation --- apps/sim/lib/auth/connectors/providers.ts | 1 + apps/sim/lib/oauth/oauth.test.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/apps/sim/lib/auth/connectors/providers.ts b/apps/sim/lib/auth/connectors/providers.ts index 314e71b0631..7167aa890f8 100644 --- a/apps/sim/lib/auth/connectors/providers.ts +++ b/apps/sim/lib/auth/connectors/providers.ts @@ -1754,6 +1754,7 @@ export function buildConnectorProviders(): GenericOAuthConfig[] { pkce: true, authentication: 'post', redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/monday`, + authorizationUrlParams: { force_install_if_needed: 'true' }, getToken: async ({ code, codeVerifier, redirectURI }) => { if (!codeVerifier) { throw new Error('Monday OAuth token exchange requires a PKCE verifier') diff --git a/apps/sim/lib/oauth/oauth.test.ts b/apps/sim/lib/oauth/oauth.test.ts index d5411450953..e4d9ffb3aa0 100644 --- a/apps/sim/lib/oauth/oauth.test.ts +++ b/apps/sim/lib/oauth/oauth.test.ts @@ -178,6 +178,7 @@ describe('Monday OAuth connector', () => { pkce: true, authentication: 'post', redirectURI: 'http://localhost:3000/api/auth/oauth2/callback/monday', + authorizationUrlParams: { force_install_if_needed: 'true' }, }) const authorizationUrl = await createAuthorizationURL({ id: connector.providerId, @@ -192,12 +193,14 @@ describe('Monday OAuth connector', () => { scopes: connector.scopes, redirectURI: connector.redirectURI!, responseType: connector.responseType, + additionalParams: connector.authorizationUrlParams, }) expect(authorizationUrl.searchParams.get('redirect_uri')).toBe( 'http://localhost:3000/api/auth/oauth2/callback/monday' ) expect(authorizationUrl.searchParams.get('scope')).toBe(connector.scopes?.join(' ')) + expect(authorizationUrl.searchParams.get('force_install_if_needed')).toBe('true') expect(authorizationUrl.searchParams.get('code_challenge_method')).toBe('S256') expect(authorizationUrl.searchParams.get('code_challenge')).toBeTruthy() }) From 7964c111134f7a34f44eb53c48ccb0151a347470 Mon Sep 17 00:00:00 2001 From: Bill Leoutsakos Date: Thu, 3 Sep 2026 09:46:44 -0700 Subject: [PATCH 2/2] test(monday): exercise OAuth link route --- apps/sim/lib/oauth/oauth.test.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/sim/lib/oauth/oauth.test.ts b/apps/sim/lib/oauth/oauth.test.ts index e4d9ffb3aa0..d829a91b48b 100644 --- a/apps/sim/lib/oauth/oauth.test.ts +++ b/apps/sim/lib/oauth/oauth.test.ts @@ -1,5 +1,7 @@ import { createMockFetch, resetEnvMock, setEnv } from '@sim/testing' -import { createAuthorizationURL, getOAuth2Tokens } from 'better-auth/oauth2' +import { getOAuth2Tokens } from 'better-auth/oauth2' +import { genericOAuth } from 'better-auth/plugins' +import { getTestInstance } from 'better-auth/test' import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' beforeAll(() => { @@ -180,21 +182,19 @@ describe('Monday OAuth connector', () => { redirectURI: 'http://localhost:3000/api/auth/oauth2/callback/monday', authorizationUrlParams: { force_install_if_needed: 'true' }, }) - const authorizationUrl = await createAuthorizationURL({ - id: connector.providerId, - options: { - clientId: connector.clientId, - clientSecret: connector.clientSecret, - redirectURI: connector.redirectURI, + const { auth, signInWithTestUser } = await getTestInstance({ + baseURL: 'http://localhost:3000', + plugins: [genericOAuth({ config: [connector] })], + }) + const { headers } = await signInWithTestUser() + const { url } = await auth.api.oAuth2LinkAccount({ + body: { + providerId: connector.providerId, + callbackURL: 'http://localhost:3000/workspace', }, - authorizationEndpoint: connector.authorizationUrl!, - state: 'state-1', - codeVerifier: 'a'.repeat(128), - scopes: connector.scopes, - redirectURI: connector.redirectURI!, - responseType: connector.responseType, - additionalParams: connector.authorizationUrlParams, + headers, }) + const authorizationUrl = new URL(url) expect(authorizationUrl.searchParams.get('redirect_uri')).toBe( 'http://localhost:3000/api/auth/oauth2/callback/monday'