6 Commits

Author SHA1 Message Date
Thigazhezhilan J
4922ea69e8 Fix auto-login OAuth context not being established
Root cause: X-Kite-Version header on web login endpoints caused Zerodha
to return plain profile response instead of OAuth redirect_url.

Changes:
- Remove X-Kite-Version from session headers (only valid for Kite Connect API)
- Use allow_redirects=False on connect/login GET to preserve OAuth cookie
- Add Referer header to login/twofa POSTs
- Check data.redirect_url in twofa JSON body (modern Zerodha SPA behavior)
- Keep Location header fallback for legacy behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 21:42:25 +05:30
Thigazhezhilan J
a1b19b7431 Add debug logging to auto-login twofa step
Prints twofa response status, Location header, and body so we can see
exactly what Zerodha returns after TOTP submission.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 21:30:03 +05:30
Thigazhezhilan J
df137afcbd Fix auto-login: initialize Zerodha OAuth session before credentials
Without first GETting the connect/login URL with the api_key,
Zerodha doesn't know which app is logging in and never returns
a request_token after TOTP — causing the redirect loop to fail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 20:59:18 +05:30
Thigazhezhilan J
1b3be0437d Gracefully handle missing pyotp so backend always starts 2026-05-02 15:34:09 +05:30
Thigazhezhilan J
f5762de2b4 Fix startup crash by importing pyotp lazily inside function 2026-05-02 15:31:13 +05:30
Thigazhezhilan J
94f175668a Add automated daily Zerodha token refresh (auto-login)
- New auto_login_service.py: stores encrypted credentials (login ID,
  password, TOTP secret), performs headless Zerodha login via pyotp,
  and refreshes the session daily at 6:05 AM IST via background thread
- New auto_login router: setup, status, remove, and manual trigger endpoints
- Scheduler started at app boot alongside existing daemons
- Added pyotp==2.9.0 dependency

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-02 12:47:21 +05:30