-
-
Notifications
You must be signed in to change notification settings - Fork 8
Add SkyFi MCP Satellite Imagery Connection and Tool Integration #748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
330af80
feat: Add SkyFi MCP satellite imagery OAuth connection and tool integ…
google-labs-jules[bot] be3bf05
feat: Fix Type error in skyfi-section and integrate SkyFi MCP satelli…
google-labs-jules[bot] 65afa91
feat: Implement secure SkyFi OAuth 2.1 connection and satellite image…
google-labs-jules[bot] 029c1ba
feat: Complete robust secure SkyFi OAuth 2.1 integration and tool ref…
google-labs-jules[bot] 2e1aceb
Implement AES-256-GCM encryption, secure initialization, and improve …
google-labs-jules[bot] 33fcb76
Dynamically resolve redirect URI for SkyFi OAuth and address PR feedback
google-labs-jules[bot] bb90e0d
Add legacy CBC decryption backwards compatibility to encryption utility
google-labs-jules[bot] b722344
Force client re-registration during SkyFi connection initiation
google-labs-jules[bot] 974fc40
Merge pull request #751 from QueueLab/jules-10643214369324289359-a5c1…
ngoiyaeric a9b2d31
fix: route unauthenticated users to SkyFi sign-in page for MCP connec…
86be866
fix: remove Discord account tab and button from Settings
fc7b417
fix: hide Discord Account tab from Settings UI while preserving backe…
a5fbc12
Merge branch 'main' into jules-5330974344690781074-fa3b2eb8
ngoiyaeric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { NextResponse, NextRequest } from 'next/server'; | ||
| import { getCurrentUserIdOnServer } from '@/lib/auth/get-current-user'; | ||
| import { SkyfiOAuthProvider } from '@/lib/skyfi/provider'; | ||
| import { getRedirectUri } from '@/lib/actions/skyfi'; | ||
| import { db } from '@/lib/db'; | ||
| import { skyfiOAuthTokens } from '@/lib/db/schema'; | ||
| import { eq } from 'drizzle-orm'; | ||
|
|
||
| export async function GET(request: NextRequest) { | ||
| try { | ||
| const userId = await getCurrentUserIdOnServer(); | ||
| if (!userId) { | ||
| return NextResponse.json({ error: 'Unauthorized: No user session found.' }, { status: 401 }); | ||
| } | ||
|
|
||
| const { searchParams } = new URL(request.url); | ||
| const code = searchParams.get('code'); | ||
| const state = searchParams.get('state'); | ||
|
|
||
| if (!code || !state) { | ||
| return NextResponse.json({ error: 'Missing code or state parameters.' }, { status: 400 }); | ||
| } | ||
|
|
||
| const redirectUri = await getRedirectUri(); | ||
| const provider = new SkyfiOAuthProvider(userId, redirectUri); | ||
|
|
||
| const storedState = await provider.state(); | ||
| if (state !== storedState) { | ||
| return NextResponse.json({ error: 'CSRF State mismatch.' }, { status: 400 }); | ||
| } | ||
|
|
||
| const clientInfo = await provider.clientInformation(); | ||
| const verifier = await provider.codeVerifier(); | ||
|
|
||
| if (!clientInfo?.client_id || !verifier) { | ||
| return NextResponse.json({ error: 'Missing client registration or PKCE verifier.' }, { status: 400 }); | ||
| } | ||
|
|
||
| console.log('[SkyFiCallback] Exchanging code for tokens with a 10s timeout...'); | ||
|
|
||
| const controller = new AbortController(); | ||
| const timeoutId = setTimeout(() => controller.abort(), 10000); | ||
|
|
||
| try { | ||
| const response = await fetch('https://mcp.skyfi.com/oauth/token', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/x-www-form-urlencoded', | ||
| }, | ||
| body: new URLSearchParams({ | ||
| grant_type: 'authorization_code', | ||
| client_id: clientInfo.client_id, | ||
| code, | ||
| redirect_uri: redirectUri, | ||
| code_verifier: verifier, | ||
| }), | ||
| signal: controller.signal, | ||
| }); | ||
|
|
||
| clearTimeout(timeoutId); | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| console.error('[SkyFiCallback] Token exchange failed:', errorText); | ||
| return NextResponse.json({ error: `Token exchange failed: ${errorText}` }, { status: 500 }); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| console.log('[SkyFiCallback] Code successfully exchanged for tokens.'); | ||
|
|
||
| // Save tokens in database | ||
| await provider.saveTokens({ | ||
| access_token: data.access_token, | ||
| refresh_token: data.refresh_token || undefined, | ||
| expires_at: data.expires_in ? Math.floor(Date.now() / 1000) + data.expires_in : undefined, | ||
| }); | ||
|
|
||
| // Clear temporary state and code verifier | ||
| await db.update(skyfiOAuthTokens) | ||
| .set({ | ||
| state: null, | ||
| codeVerifier: null, | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where(eq(skyfiOAuthTokens.userId, userId)); | ||
|
|
||
| } catch (fetchError: any) { | ||
| clearTimeout(timeoutId); | ||
| console.error('[SkyFiCallback] Fetch failed or timed out:', fetchError.message); | ||
| return NextResponse.json({ error: `Token exchange failed or timed out: ${fetchError.message}` }, { status: 500 }); | ||
| } | ||
|
|
||
| // Redirect user back to the settings page | ||
| const baseUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'; | ||
| return NextResponse.redirect(`${baseUrl}/settings`); | ||
| } catch (error: any) { | ||
| console.error('[SkyFiCallback] Unexpected error:', error.message); | ||
| const baseUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'; | ||
| return NextResponse.redirect(`${baseUrl}/settings?error=skyfi_callback_failed`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.