Codebuff implements secure authentication between CLI (npm-app), backend, and web application using fingerprint-based device identification.
sequenceDiagram
participant CLI as npm-app
participant Web as web app
participant DB as Database
CLI->>Web: POST /api/auth/cli/code {fingerprintId}
Web->>Web: Generate auth code (1h expiry)
Web->>CLI: Return login URL
CLI->>CLI: Open browser
Note over Web: User completes OAuth
Web->>DB: Check fingerprint ownership
Web->>DB: Create/update session
loop Every 5s
CLI->>Web: GET /api/auth/cli/status
Web->>DB: Check session
end
- CLI generates fingerprint from hardware info + 8 random bytes
- Uses
calculateFingerprint()innpm-app/src/fingerprint.ts - Continues to core flow with new fingerprintId
- CLI calls POST
/api/auth/cli/logout - Deletes session from database
- Resets fingerprint
sig_hashto null (unclaimed) - Deletes local
credentials.json
- Web creates fingerprint record in database
- Creates new session with fingerprint_id
- Returns user credentials to CLI
- Web finds existing fingerprint
- Verifies ownership via
sig_hashmatch or null value - Updates/creates session
- Returns user credentials to CLI
- Fingerprint exists with different
sig_hash - Logs security event
- Returns authentication error
- Auth code validation fails or expired (1h limit)
- Returns authentication error
- Auth codes expire after 1 hour
- Fingerprint uniqueness: hardware info + 8 random bytes
- Ownership conflicts blocked and logged
- Sessions linked to fingerprint_id in database
- Logout resets fingerprint to unclaimed state
fingerprint: Stores device fingerprints withsig_hashfor ownershipsession: Links users to fingerprints with expirationuser: Stores user account information
- Fingerprint Management: Use existing fingerprintId from credentials when available, only generate new ones for first-time users
- Session Handling: Sessions are tied to fingerprint_id and have expiration dates
- Ownership Verification: Check
sig_hashmatches or is null before allowing access - Error Handling: Log security events for ownership conflicts and invalid attempts