Google Drive Integration
Enable Google Drive integration to import medical documents and export diagnosis reports directly to Google Drive.
Overview
The Google Drive integration allows users to:
- Import medical documents from Google Drive
- Export diagnosis reports to Google Drive
- Sync case files with Google Drive
Prerequisites
Before setting up Google Drive integration, you need:
- Google Cloud Project: Create a project in Google Cloud Console
- OAuth 2.0 Credentials: Set up OAuth 2.0 credentials
- Google Drive API: Enable the Google Drive API
- Client ID: Obtain your OAuth 2.0 client ID
Setup Instructions
Step 1: Create Google Cloud Project
- Go to Google Cloud Console
- Click "Select a project" → "New Project"
- Enter project name (e.g., "My Medical App")
- Click "Create"
Step 2: Enable Google Drive API
- In Google Cloud Console, go to "APIs & Services" → "Library"
- Search for "Google Drive API"
- Click "Enable"
Step 3: Create OAuth 2.0 Credentials
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth client ID"
- If prompted, configure the OAuth consent screen:
- User Type: External (or Internal for Google Workspace)
- App name: Your application name
- User support email: Your email
- Developer contact: Your email
- Click "Save and Continue"
- Add scopes (optional for testing):
- Click "Add or Remove Scopes"
- Add
https://www.googleapis.com/auth/drive.file - Click "Update" → "Save and Continue"
- Add test users (for external apps in testing):
- Add email addresses of users who can test
- Click "Save and Continue"
- Return to "Credentials"
- Click "Create Credentials" → "OAuth client ID"
- Application type: "Web application"
- Name: "Knidian SDK Integration"
- Authorized JavaScript origins:
- Add your application URLs:
https://yourdomain.com
http://localhost:3000 (for development)
- Add your application URLs:
- Authorized redirect URIs (not required for SDK, but recommended):
https://yourdomain.com
http://localhost:3000 (for development) - Click "Create"
- Copy your Client ID (looks like
123456789-abc123.apps.googleusercontent.com)
Step 4: Configure SDK
Add your Google OAuth 2.0 Client ID to the SDK configuration:
const sdk = KnidianSDK.create({
authUrl: 'https://your-backend.com/api/knidian-auth',
userId: 'user-123',
container: '#app',
// Enable Google Drive integration
googleDrive: {
clientId: '123456789-abc123.apps.googleusercontent.com'
}
});
Step 5: Configure Environment Variables
Store your Client ID securely:
# .env file
GOOGLE_CLIENT_ID=123456789-abc123.apps.googleusercontent.com
// Use in your app
const sdk = KnidianSDK.create({
authUrl: 'https://your-backend.com/api/knidian-auth',
userId: currentUser.id,
container: '#app',
googleDrive: {
clientId: process.env.GOOGLE_CLIENT_ID
}
});
Usage
Importing Documents from Google Drive
Once configured, users can import documents directly from their Google Drive:
- Click the "Upload" or "Import" button in the SDK
- Select "Import from Google Drive"
- Authenticate with Google (first time only)
- Browse and select files from Google Drive
- Files are imported into the current case
Exporting Diagnoses to Google Drive
Export diagnosis reports to Google Drive:
- Complete a diagnosis
- Click "Export" in the diagnosis panel
- Select "Export to Google Drive"
- Choose destination folder (or use root)
- File is saved as
Diagnosis_Report_[CaseID].pdfor.docx
Features
Supported File Types
Import from Google Drive
- Images: JPEG, PNG, GIF
- Documents: PDF, DOC, DOCX
- Medical files: DICOM (if enabled)
Export to Google Drive
- PDF reports
- DOCX reports
- JSON data (if enabled)
Authentication Flow
The SDK handles Google OAuth 2.0 authentication automatically:
- First Use: User clicks "Connect Google Drive"
- Consent: Google OAuth consent screen appears
- Authorization: User grants permission to access Drive
- Token Storage: Access token stored securely in browser
- Auto-Refresh: Tokens refreshed automatically
Permissions Required
The SDK requests minimal permissions:
- Scope:
https://www.googleapis.com/auth/drive.file - Access: Only files created by the SDK
- No Access To: User's other Google Drive files
Advanced Configuration
Custom Scopes
Request additional Google Drive permissions:
// Note: SDK currently uses drive.file scope only
// Contact support@knidian.ai for custom scope requirements
Custom Export Folder
Specify default export folder:
// This feature is currently handled by user selection
// during export. Custom default folders may be added in future releases.
Security Considerations
Client ID Security
Important: The Google OAuth Client ID is NOT a secret. It's safe to include in your client-side code.
However, for additional security:
-
Restrict HTTP Referrers: In Google Cloud Console
- Go to Credentials → Edit OAuth 2.0 Client ID
- Under "Authorized JavaScript origins"
- Limit to your production domains only
-
Use Application Restrictions:
- Restrict the Client ID to specific domains
- Remove
localhostbefore production deployment
User Data Privacy
The SDK:
- Only accesses files it creates (via
drive.filescope) - Does NOT access user's existing Google Drive files
- Stores access tokens in browser localStorage
- Automatically revokes access on logout
HIPAA Compliance
For HIPAA compliance with Google Drive:
- Google Workspace: Use Google Workspace (Business or Enterprise)
- BAA with Google: Ensure you have a Business Associate Agreement with Google
- Encryption: All files encrypted in transit and at rest by Google
- Access Logs: Enable Google Drive audit logs
Contact compliance@knidian.ai for HIPAA guidance.
Troubleshooting
Error: "Invalid Client ID"
Cause: Client ID is incorrect or not properly configured
Solution:
- Verify Client ID in Google Cloud Console
- Ensure it's copied correctly (no extra spaces)
- Check that Google Drive API is enabled
- Verify authorized JavaScript origins include your domain
Error: "Access Denied"
Cause: User denied permission or app not verified
Solution:
- User must click "Allow" in OAuth consent screen
- If app is unverified, user must click "Advanced" → "Go to [App Name] (unsafe)"
- For production, submit app for Google verification
Error: "Redirect URI Mismatch"
Cause: The redirect URI doesn't match configured URIs
Solution:
- Go to Google Cloud Console → Credentials
- Edit OAuth 2.0 Client ID
- Add your current URL to "Authorized JavaScript origins"
- Include both production and development URLs
Files Not Appearing in Google Drive
Cause: Files may be in "Shared with me" or different folder
Solution:
- Check "My Drive" in Google Drive
- Search for file by name (e.g., "Diagnosis_Report")
- Files created by SDK appear in root or selected folder
Authentication Loop
Cause: Popup blocker or localStorage issues
Solution:
- Disable popup blockers for your domain
- Clear browser localStorage
- Try in incognito/private mode
- Check browser console for errors
Testing
Development Testing
Test Google Drive integration in development:
const sdk = KnidianSDK.create({
authUrl: 'http://localhost:3000/api/knidian-auth',
userId: 'test-user',
container: '#app',
googleDrive: {
clientId: process.env.GOOGLE_CLIENT_ID // Uses localhost in dev
}
});
Remember:
- Add
http://localhost:3000to authorized origins - Add test user emails to OAuth consent screen
- Use test/dev Google account
Production Checklist
Before deploying to production:
- Google Drive API enabled
- OAuth 2.0 Client ID created
- Production domain added to authorized origins
- OAuth consent screen configured
- Client ID stored in environment variables
- Test import functionality
- Test export functionality
- Verify files appear in Google Drive
- Test with multiple users
- Remove localhost from authorized origins
App Verification (Production)
For production apps with many users, Google requires app verification.
When Verification is Required
- External users (non-Google Workspace)
- More than 100 users
- Sensitive or restricted scopes
Verification Process
- Go to Google Cloud Console
- Navigate to "OAuth consent screen"
- Click "Publish App"
- Submit for verification:
- Company homepage
- Privacy policy URL
- Terms of service URL
- App logo
- App verification video (if required)
- Wait for Google review (1-3 weeks typically)
Note: Apps in testing mode can have up to 100 test users without verification.
API Quotas
Google Drive API has usage quotas:
- Queries per 100 seconds: 1,000
- Queries per day: 1,000,000,000
These limits are more than sufficient for typical SDK usage.
Monitor Usage
- Go to Google Cloud Console
- Navigate to "APIs & Services" → "Dashboard"
- Click "Google Drive API"
- View usage metrics
Examples
Complete Setup Example
// .env
GOOGLE_CLIENT_ID=123456789-abc123.apps.googleusercontent.com
// app.js
const sdk = KnidianSDK.create({
authUrl: 'https://your-backend.com/api/knidian-auth',
userId: currentUser.id,
container: '#knidian-container',
// Enable Google Drive
googleDrive: {
clientId: process.env.GOOGLE_CLIENT_ID
}
});
console.log('SDK initialized with Google Drive support');
Monitoring Google Drive Usage
Event callbacks (onFileUploaded, onError) are not yet available. Track Google Drive usage through your backend logs.
Current approach:
const sdk = KnidianSDK.create({
authUrl: 'https://your-backend.com/api/knidian-auth',
userId: currentUser.id,
container: '#app',
googleDrive: {
clientId: process.env.GOOGLE_CLIENT_ID
}
});
// Users can import/export files via the SDK UI
// Track usage through your backend auth endpoint logs
Disabling Google Drive
To disable Google Drive integration, simply omit the googleDrive configuration:
const sdk = KnidianSDK.create({
authUrl: 'https://your-backend.com/api/knidian-auth',
userId: 'user-123',
container: '#app'
// No googleDrive config = disabled
});
Users will not see Google Drive import/export options.
Best Practices
- Use Environment Variables: Never hardcode Client ID in source code committed to version control
- Restrict Origins: Limit authorized origins to your actual domains
- Test Thoroughly: Test import and export with various file types
- Handle Errors: Implement proper error handling for OAuth failures
- User Education: Provide help text explaining Google Drive permissions
- Monitor Usage: Track Google Drive API usage in Google Cloud Console
- Security: Review and update OAuth consent screen information regularly
Future Enhancements
Planned features:
- Auto-sync case files to Google Drive
- Folder organization options
- Batch export
- Import from Google Sheets (structured data)
Contact features@knidian.ai to request specific Google Drive features.
Support
For Google Drive integration issues:
- SDK Integration: support@knidian.ai
- Google OAuth: Google OAuth Documentation
- Google Drive API: Google Drive API Documentation
Next Steps
- Configuration Guide: Complete configuration reference
- Security: Security best practices
- Troubleshooting: Common issues and solutions
- Customization: Advanced customization