-
Notifications
You must be signed in to change notification settings - Fork 1
Adds Google Drive OAuth support #75
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
4 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -61,8 +61,9 @@ export async function handleConnectionDone(req: Request, res: Response): Promise | |
| // Build multi-provider tokens structure for JWT creation | ||
| const atlassianTokens = providerTokens['atlassian']; | ||
| const figmaTokens = providerTokens['figma']; | ||
| const googleTokens = providerTokens['google']; | ||
|
|
||
| if (!atlassianTokens && !figmaTokens) { | ||
| if (!atlassianTokens && !figmaTokens && !googleTokens) { | ||
| throw new Error('No provider tokens found - please connect at least one service'); | ||
| } | ||
|
|
||
|
|
@@ -93,6 +94,18 @@ export async function handleConnectionDone(req: Request, res: Response): Promise | |
| console.log(' Warning: Figma tokens incomplete (missing access or refresh token)'); | ||
| } | ||
|
|
||
| if (googleTokens && googleTokens.access_token && googleTokens.refresh_token) { | ||
| console.log(' Adding Google credentials to JWT'); | ||
| multiProviderTokens.google = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar here, this code is the same for each provider
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before. This can be added to the next ticket for authentication improvement. |
||
| access_token: googleTokens.access_token, | ||
| refresh_token: googleTokens.refresh_token, | ||
| expires_at: googleTokens.expires_at, | ||
| scope: googleTokens.scope, | ||
| }; | ||
| } else if (googleTokens) { | ||
| console.log(' Warning: Google tokens incomplete (missing access or refresh token)'); | ||
| } | ||
|
|
||
| // Create JWT access token with nested provider structure | ||
| const tokenOptions = { | ||
| resource: req.session.mcpResource || process.env.VITE_AUTH_SERVER_URL, | ||
|
|
||
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,66 @@ | ||
| /** | ||
| * Google Drive API Client Factory | ||
| * | ||
| * Provides API client instances for OAuth authentication. | ||
| * Uses native fetch (no additional dependencies). | ||
| * | ||
| * Authentication Methods: | ||
| * - OAuth: Uses Bearer tokens from OAuth 2.0 flow (for user delegation) | ||
| */ | ||
|
|
||
| import type { DriveAboutResponse } from './types.js'; | ||
|
|
||
| /** | ||
| * Google API client interface | ||
| * | ||
| * Provides methods for making authenticated requests to Google APIs. | ||
| * All methods have the access token pre-configured via closure. | ||
| */ | ||
| export interface GoogleClient { | ||
| /** | ||
| * Make an authenticated fetch request to Google API | ||
| * @param url - The full URL to fetch | ||
| * @param options - Standard fetch options (method, body, etc.) | ||
| * @returns Promise resolving to fetch Response | ||
| */ | ||
| fetch: (url: string, options?: RequestInit) => Promise<Response>; | ||
|
|
||
| /** | ||
| * Authentication type used by this client | ||
| */ | ||
| authType: 'oauth'; | ||
| } | ||
|
|
||
| /** | ||
| * Create a Google API client using OAuth access token | ||
| * @param accessToken - OAuth 2.0 Bearer token | ||
| * @returns API client with Drive operations | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const client = createGoogleClient(token); | ||
| * | ||
| * // Fetch with auth automatically included | ||
| * const response = await client.fetch( | ||
| * 'https://www.googleapis.com/drive/v3/about?fields=user', | ||
| * { method: 'GET' } | ||
| * ); | ||
| * ``` | ||
| */ | ||
| export function createGoogleClient(accessToken: string): GoogleClient { | ||
| return { | ||
| authType: 'oauth', | ||
|
|
||
| fetch: async (url: string, options: RequestInit = {}) => { | ||
| // Token is captured in this closure! | ||
| return fetch(url, { | ||
| ...options, | ||
| headers: { | ||
| ...options.headers, | ||
| 'Authorization': `Bearer ${accessToken}`, | ||
| 'Accept': 'application/json', | ||
| }, | ||
| }); | ||
| }, | ||
| }; | ||
| } |
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,31 @@ | ||
| /** | ||
| * Google Drive API interaction helpers | ||
| * Reusable functions for Google Drive API calls | ||
| */ | ||
|
|
||
| import type { GoogleClient } from './google-api-client.js'; | ||
| import type { DriveAboutResponse } from './types.js'; | ||
|
|
||
| /** | ||
| * Get the authenticated user's Google Drive information | ||
| * @param client - Authenticated Google API client | ||
| * @returns Promise resolving to Drive user information | ||
| * @throws Error if the API request fails | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * const client = createGoogleClient(token); | ||
| * const userData = await getGoogleDriveUser(client); | ||
| * console.log(userData.user.emailAddress); | ||
| * ``` | ||
| */ | ||
| export async function getGoogleDriveUser(client: GoogleClient): Promise<DriveAboutResponse> { | ||
| const response = await client.fetch('https://www.googleapis.com/drive/v3/about?fields=user'); | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| throw new Error(`Drive API error (${response.status}): ${errorText}`); | ||
| } | ||
|
|
||
| return response.json() as Promise<DriveAboutResponse>; | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do some cleanup to make our auth providers more abstract and code like this just loops through them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest creating a new ticket to improve the overall authentication code. I would rather not add new code to the current implementation on this MR. Do you mind creating a ticket and assigning it to me?