Skip to content

Commit 28e13b7

Browse files
committed
fix(auth): add expiry check, credentials, MCP CORS, and scope in WWW-Authenticate
1 parent 312e545 commit 28e13b7

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

apps/sim/app/(auth)/oauth/consent/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ export default function OAuthConsentPage() {
102102
const handleSwitchAccount = useCallback(async () => {
103103
if (!consentCode) return
104104

105-
const res = await fetch(`/api/auth/oauth2/authorize-params?consent_code=${consentCode}`)
105+
const res = await fetch(`/api/auth/oauth2/authorize-params?consent_code=${consentCode}`, {
106+
credentials: 'include',
107+
})
106108
if (!res.ok) {
107109
setError('Unable to switch accounts. Please re-initiate the connection.')
108110
return

apps/sim/app/api/auth/oauth2/authorize-params/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { db } from '@sim/db'
22
import { verification } from '@sim/db/schema'
3-
import { eq } from 'drizzle-orm'
3+
import { and, eq, gt } from 'drizzle-orm'
44
import type { NextRequest } from 'next/server'
55
import { NextResponse } from 'next/server'
66
import { getSession } from '@/lib/auth'
@@ -24,7 +24,7 @@ export async function GET(request: NextRequest) {
2424
const [record] = await db
2525
.select({ value: verification.value })
2626
.from(verification)
27-
.where(eq(verification.identifier, consentCode))
27+
.where(and(eq(verification.identifier, consentCode), gt(verification.expiresAt, new Date())))
2828
.limit(1)
2929

3030
if (!record) {

apps/sim/app/api/mcp/copilot/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ export async function POST(request: NextRequest) {
544544
return new NextResponse(JSON.stringify({ error: 'unauthorized' }), {
545545
status: 401,
546546
headers: {
547-
'WWW-Authenticate': `Bearer resource_metadata="${resourceMetadataUrl}"`,
547+
'WWW-Authenticate': `Bearer resource_metadata="${resourceMetadataUrl}", scope="mcp:tools"`,
548548
'Content-Type': 'application/json',
549549
},
550550
})

apps/sim/next.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ const nextConfig: NextConfig = {
179179
{ key: 'Access-Control-Allow-Headers', value: 'Content-Type, Accept' },
180180
],
181181
},
182+
{
183+
source: '/api/mcp/copilot',
184+
headers: [
185+
{ key: 'Access-Control-Allow-Credentials', value: 'false' },
186+
{ key: 'Access-Control-Allow-Origin', value: '*' },
187+
{
188+
key: 'Access-Control-Allow-Methods',
189+
value: 'GET, POST, OPTIONS, DELETE',
190+
},
191+
{
192+
key: 'Access-Control-Allow-Headers',
193+
value: 'Content-Type, Authorization, X-API-Key, X-Requested-With, Accept',
194+
},
195+
],
196+
},
182197
// For workflow execution API endpoints
183198
{
184199
source: '/api/workflows/:id/execute',

0 commit comments

Comments
 (0)