This document explains how to set up and use the new Google Drive and OneDrive sync services that have been added to the Document Scanner app.
The sync services use OAuth 2.0 authentication to securely access your cloud storage. Due to security best practices, OAuth client credentials cannot be included in the open-source repository. You must create your own OAuth applications with Google and Microsoft to use these features.
- Go to the Google Cloud Console
- Create a new project or select an existing one
- In the sidebar, navigate to APIs & Services > Library
- Search for "Google Drive API" and enable it
- Navigate to APIs & Services > OAuth consent screen
- Choose External user type (unless you have a Google Workspace account)
- Fill in the required information:
- App name: "Document Scanner" (or your app name)
- User support email: Your email
- Developer contact information: Your email
- Add the required scope:
https://www.googleapis.com/auth/drive.file - Save and continue
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Android as the application type
- Enter the package name:
com.akylas.documentscanner(or your package name) - Get your SHA-1 certificate fingerprint:
keytool -list -v -keystore path/to/your/keystore -alias your-key-alias
- Copy the OAuth client ID
- Create credentials with iOS as the application type
- Enter your Bundle ID
- Copy the OAuth client ID
Edit app/services/sync/GoogleDrive.ts:
export const GOOGLE_DRIVE_PROVIDER: OAuthProvider = {
name: 'Google Drive',
config: {
authUrl: 'https://accounts.google.com/o/oauth2/v2/auth',
tokenUrl: 'https://oauth2.googleapis.com/token',
clientId: 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com', // Replace this
redirectUri: 'com.akylas.documentscanner.oauth:/oauth2redirect',
scope: 'https://www.googleapis.com/auth/drive.file',
responseType: 'code'
}
};Replace YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com with your actual client ID.
- Go to the Azure Portal
- Navigate to Azure Active Directory > App registrations
- Click New registration
- Enter application details:
- Name: "Document Scanner" (or your app name)
- Supported account types: Choose appropriate option (usually "Accounts in any organizational directory and personal Microsoft accounts")
- Click Register
- In your app registration, go to Authentication
- Click Add a platform
- For Android:
- Select Android
- Enter package name:
com.akylas.documentscanner - Enter signature hash
- For iOS:
- Select iOS / macOS
- Enter Bundle ID
- Add redirect URI:
com.akylas.documentscanner.oauth:/oauth2redirect - Save changes
- Go to API permissions
- Click Add a permission > Microsoft Graph
- Select Delegated permissions
- Add these permissions:
Files.ReadWriteoffline_access
- Click Add permissions
- Go to Overview tab
- Copy the Application (client) ID
Edit app/services/sync/OneDrive.ts:
export const ONEDRIVE_PROVIDER: OAuthProvider = {
name: 'OneDrive',
config: {
authUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
tokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
clientId: 'YOUR_ONEDRIVE_CLIENT_ID', // Replace this
redirectUri: 'com.akylas.documentscanner.oauth:/oauth2redirect',
scope: 'files.readwrite offline_access',
responseType: 'code'
}
};Replace YOUR_ONEDRIVE_CLIENT_ID with your actual client ID.
- Open the app and go to Settings > Sync
- Tap the Add button (+)
- Select your desired service type:
- Google Drive (Data, Image, or PDF)
- OneDrive (Data, Image, or PDF)
- Configure the service:
- Tap Authenticate to log in with your account
- Set the remote folder path (default: "DocumentScanner")
- Choose a color for identification
- Enable/disable auto-sync
- Tap Save
- Data Sync: Syncs document metadata and folder structures
- Image Sync: Syncs document images (pages)
- PDF Sync: Syncs exported PDF files
You can enable multiple sync types simultaneously for comprehensive backup.
To manually trigger a sync:
- Go to Settings > Sync
- Tap on the configured sync service
- Use the sync options in the menu
When enabled, changes are automatically synced when:
- A document is created or modified
- Pages are added or removed
- The app is online and connected
- Verify your client ID is correctly configured
- Ensure the redirect URI matches exactly
- Check that the app signature/bundle ID is correct
- User cancelled the login process
- Try authenticating again
- Ensure you granted the necessary permissions in your OAuth app
- For Google Drive: Check that the Drive API is enabled
- For OneDrive: Verify the Microsoft Graph permissions are added
- Check internet connectivity
- Verify the OAuth tokens haven't expired (they auto-refresh if possible)
- Check the remote folder path is correct
- Review app logs for errors
- Tokens automatically refresh using the refresh token
- If refresh fails, re-authenticate from settings
- The implementation uses OAuth 2.0 with PKCE (Proof Key for Code Exchange) for enhanced security
- This prevents authorization code interception attacks
- Access tokens are stored in ApplicationSettings
- On iOS: Encrypted in keychain
- On Android: Stored in SharedPreferences (consider using encrypted shared preferences for production)
- Google Drive: Only accesses files created by the app (
drive.filescope) - OneDrive: Only accesses user's files with explicit permission
-
File Size: Current implementation uses simple upload. Files over 4MB may fail on OneDrive. Consider implementing resumable uploads for production.
-
Rate Limiting: No rate limiting implemented. API quota may be exceeded with heavy usage.
-
Offline Support: Limited offline capability. Requires network connection for sync operations.
-
Conflict Resolution: Basic conflict handling. Newer files overwrite older ones.
Before deploying, test:
- Authentication flow on Android and iOS
- File upload/download operations
- Folder creation and navigation
- Token refresh after expiration
- Network error handling
- Multiple document sync
- Large file handling
For production deployment:
- Implement Resumable Uploads: For files larger than 4MB, implement resumable upload APIs
- Add Rate Limiting: Implement exponential backoff and retry logic
- Improve Token Storage: Use encrypted storage for sensitive tokens
- Add Conflict Resolution UI: Let users choose how to handle conflicts
- Implement Batch Operations: Improve performance with batch API calls
- Add Quota Monitoring: Monitor API usage and warn users
- Error Recovery: Implement robust error recovery and offline queue
For issues or questions:
- Check the logs (enable DEV_LOG in the code)
- Review the OAuth provider's documentation
- Check API quotas and limits
- Open an issue on the repository with details
- Google Drive API Documentation
- Microsoft Graph Files API
- OAuth 2.0 with PKCE
- NativeScript WebView Plugin
This implementation is part of the Document Scanner project and follows the same license (MIT).