Overview
StreamVault uses a backend server to handle Google OAuth securely. The client never sees OAuth client secrets - they remain on the server throughout the authentication flow.Why Backend OAuth?
Storing OAuth client secrets in a desktop application is insecure because:- Secrets can be extracted from compiled binaries
- Decompiled apps expose credentials to anyone
- Client secrets must be kept confidential per OAuth 2.0 spec
Authentication Flow
Endpoints
POST /auth/google
Initiates the OAuth 2.0 authorization flow. URL:https://streamvault-backend-server.onrender.com/auth/google
Method: GET (browser redirect)
Flow:
- Client opens this URL in system browser
- User authenticates with Google
- Backend exchanges authorization code for tokens
- Backend redirects to
http://localhost:8085/callback?tokens=<BASE64_JSON>
POST /auth/refresh
Refreshes an expired access token using a refresh token. URL:https://streamvault-backend-server.onrender.com/auth/refresh
Method: POST
Request Body:
Token Storage
Tokens are stored locally at: Windows:%APPDATA%/StreamVault/gdrive_tokens.json
Linux: ~/.local/share/StreamVault/gdrive_tokens.json
macOS: ~/Library/Application Support/StreamVault/gdrive_tokens.json
Format:
Token Lifecycle
Automatic Refresh
Tokens are automatically refreshed when:- Access token is expired (checked before each API call)
- Token expiration is within 60 seconds (gdrive.rs:115)
Token Expiration
Google access tokens typically expire after 1 hour (3600 seconds). Refresh tokens:- Do not expire automatically
- Can be revoked by user in Google Account settings
- Must be re-obtained if revoked
Local Callback Server
The client runs a temporary HTTP server on port 8085 to capture the OAuth callback. Implementation (gdrive.rs:752-815):Security Considerations
What’s Secure
- Client secrets never exposed to client
- Tokens transmitted via localhost (not exposed to network)
- Access tokens are short-lived (1 hour)
- Refresh tokens stored with file system permissions
What’s Not Secure
- Tokens stored in plaintext on disk
- No encryption at rest
- Local callback server uses HTTP (not HTTPS)
- Encrypting token storage with OS keychain APIs
- Using a production OAuth redirect URI with HTTPS
- Implementing token encryption/obfuscation
Error Handling
Common Errors
“No tokens in callback URL”- Backend failed to exchange authorization code
- User denied authorization
- Network error during OAuth flow
- Offline access not granted
- User revoked access in Google settings
- Re-authenticate required
- Refresh token revoked
- Backend server unreachable
- Invalid refresh token
Recovery
When token refresh fails, prompt user to re-authenticate:Testing
Test the authentication flow:Related
Backend Overview
Backend architecture and self-hosting
Google Drive API
Using authenticated Google Drive client