diff --git a/package.json b/package.json index 4e0ba2b..ddab8de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vectorize-io/vectorize-connect", - "version": "0.4.0", + "version": "0.4.1", "description": "A simple package for Google Drive authorization and file selection", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/baseOAuth/ui/picker.ts b/src/baseOAuth/ui/picker.ts index 6337ac3..1a797c1 100644 --- a/src/baseOAuth/ui/picker.ts +++ b/src/baseOAuth/ui/picker.ts @@ -213,7 +213,8 @@ export abstract class BasePicker { styles: string = '', head: string = '', body: string, - scripts: string + scripts: string, + nonce?: string ): string { return ` @@ -283,7 +284,7 @@ export abstract class BasePicker { ${body} - diff --git a/src/dropBoxOAuth/core/oauth.ts b/src/dropBoxOAuth/core/oauth.ts index 9aefed2..b43f4bb 100644 --- a/src/dropBoxOAuth/core/oauth.ts +++ b/src/dropBoxOAuth/core/oauth.ts @@ -91,7 +91,8 @@ export class DropboxOAuth extends BaseOAuth { public static override async createCallbackResponse( code: string, config: DropboxOAuthConfig, - error?: string | OAuthError + error?: string | OAuthError, + nonce?: string ): Promise { if (error) { const errorObj = typeof error === 'string' ? new OAuthError(error, 'CALLBACK_ERROR') : error; @@ -107,8 +108,8 @@ export class DropboxOAuth extends BaseOAuth { ); // Use the Dropbox picker template - const htmlContent = DropboxPicker.createPickerHTML(tokens, config, tokens.refresh_token); - + const htmlContent = DropboxPicker.createPickerHTML(tokens, config, tokens.refresh_token, undefined, nonce); + return new Response(htmlContent, { headers: { 'Content-Type': 'text/html' } }); } catch (error) { return this.createErrorResponse( diff --git a/src/dropBoxOAuth/ui/picker.ts b/src/dropBoxOAuth/ui/picker.ts index 4039397..76f98a3 100644 --- a/src/dropBoxOAuth/ui/picker.ts +++ b/src/dropBoxOAuth/ui/picker.ts @@ -16,10 +16,11 @@ export class DropboxPicker extends BasePicker { * @returns HTML string for the Dropbox picker interface */ createPickerHTML( - tokens: OAuthResponse, - config: DropboxOAuthConfig, - refreshToken: string, - preSelectedFiles?: Record + tokens: OAuthResponse, + config: DropboxOAuthConfig, + refreshToken: string, + preSelectedFiles?: Record, + nonce?: string ): string { const ui = this.getCommonUIElements(); @@ -218,7 +219,8 @@ export class DropboxPicker extends BasePicker { ${ui.fileListContainer} ${ui.submitButtonContainer} `, - dropboxScripts + dropboxScripts, + nonce ); } @@ -226,12 +228,13 @@ export class DropboxPicker extends BasePicker { * Create a static instance for backward compatibility */ static createPickerHTML( - tokens: OAuthResponse, - config: DropboxOAuthConfig, - refreshToken: string, - preSelectedFiles?: Record + tokens: OAuthResponse, + config: DropboxOAuthConfig, + refreshToken: string, + preSelectedFiles?: Record, + nonce?: string ): string { const picker = new DropboxPicker(); - return picker.createPickerHTML(tokens, config, refreshToken, preSelectedFiles); + return picker.createPickerHTML(tokens, config, refreshToken, preSelectedFiles, nonce); } } \ No newline at end of file diff --git a/src/googleDriveOAuth/core/oauth.ts b/src/googleDriveOAuth/core/oauth.ts index 370b72e..a96ea2a 100644 --- a/src/googleDriveOAuth/core/oauth.ts +++ b/src/googleDriveOAuth/core/oauth.ts @@ -96,7 +96,8 @@ export class GoogleDriveOAuth extends BaseOAuth { public static override async createCallbackResponse( code: string, config: GoogleDriveOAuthConfig, - error?: string | OAuthError + error?: string | OAuthError, + nonce?: string ): Promise { if (error) { const errorObj = typeof error === 'string' ? new OAuthError(error, 'CALLBACK_ERROR') : error; @@ -112,8 +113,8 @@ export class GoogleDriveOAuth extends BaseOAuth { ); // Use the Google Drive picker template - const htmlContent = GoogleDrivePicker.createPickerHTML(tokens, config, tokens.refresh_token); - + const htmlContent = GoogleDrivePicker.createPickerHTML(tokens, config, tokens.refresh_token, undefined, nonce); + return new Response(htmlContent, { headers: { 'Content-Type': 'text/html' } }); } catch (error) { return this.createErrorResponse( diff --git a/src/googleDriveOAuth/ui/picker.ts b/src/googleDriveOAuth/ui/picker.ts index 6a4eff5..d314115 100644 --- a/src/googleDriveOAuth/ui/picker.ts +++ b/src/googleDriveOAuth/ui/picker.ts @@ -16,10 +16,11 @@ export class GoogleDrivePicker extends BasePicker { * @returns HTML string for the Google Drive picker interface */ createPickerHTML( - tokens: OAuthResponse, - config: GoogleDriveOAuthConfig, - refreshToken: string, - preSelectedFiles?: Record + tokens: OAuthResponse, + config: GoogleDriveOAuthConfig, + refreshToken: string, + preSelectedFiles?: Record, + nonce?: string ): string { const ui = this.getCommonUIElements(); @@ -155,7 +156,8 @@ export class GoogleDrivePicker extends BasePicker { ${ui.fileListContainer} ${ui.submitButtonContainer} `, - googleDriveScripts + googleDriveScripts, + nonce ); } @@ -163,12 +165,13 @@ export class GoogleDrivePicker extends BasePicker { * Create a static instance for backward compatibility */ static createPickerHTML( - tokens: OAuthResponse, - config: GoogleDriveOAuthConfig, - refreshToken: string, - preSelectedFiles?: Record + tokens: OAuthResponse, + config: GoogleDriveOAuthConfig, + refreshToken: string, + preSelectedFiles?: Record, + nonce?: string ): string { const picker = new GoogleDrivePicker(); - return picker.createPickerHTML(tokens, config, refreshToken, preSelectedFiles); + return picker.createPickerHTML(tokens, config, refreshToken, preSelectedFiles, nonce); } } \ No newline at end of file diff --git a/src/googleDriveOAuth/utils/validation.ts b/src/googleDriveOAuth/utils/validation.ts index d9c1264..04c3cb5 100644 --- a/src/googleDriveOAuth/utils/validation.ts +++ b/src/googleDriveOAuth/utils/validation.ts @@ -1,11 +1,12 @@ -import { OAuthConfig, OAuthError, ConfigurationError } from '../types'; +import { OAuthError, ConfigurationError } from '../../baseOAuth/types'; +import { GoogleDriveOAuthConfig } from '../types'; /** * Validates the OAuth configuration * @param config The OAuth configuration to validate * @throws ConfigurationError if the configuration is invalid */ -export function validateConfig(config: OAuthConfig): void { +export function validateConfig(config: GoogleDriveOAuthConfig): void { if (!config.clientId) { throw new ConfigurationError('Client ID is required'); } diff --git a/src/notionOAuth/ui/picker.ts b/src/notionOAuth/ui/picker.ts index 9101867..4513148 100644 --- a/src/notionOAuth/ui/picker.ts +++ b/src/notionOAuth/ui/picker.ts @@ -19,7 +19,8 @@ export class NotionPicker { tokens: any, config: NotionOAuthConfig, accessToken: string, - existingSelection?: Record + existingSelection?: Record, + nonce?: string ): string { // Convert existing selection to JSON string for embedding in the HTML const existingSelectionStr = existingSelection @@ -412,7 +413,7 @@ export class NotionPicker { -