Automate TOTP login for a Zerodha Connect App.
- Download selenium webdriver from the following location:
Selenium webdriver (https://chromedriver.chromium.org/downloads)
- Read the following article to add it to your path in your OS.
How to add webdriver to PATH (https://www.browserstack.com/guide/run-selenium-tests-using-selenium-chromedriver#:~:text=Go%20to%20the%20terminal%20and,Type%20Y%20to%20save)
- Rename file
.env.example
to.env
- Fill in all the four values: (
API_KEY
,USERID
,PASSWORD
,TOTP_KEY
)
API_KEY
: Zerodha app's api key. Get it from the app you have created in zerodha connect api website.
USERID
: Kite zerodha userid. You use it to log into kite website.
PASSWORD
: Kite zerodha password. You use it to log into kite website.
TOTP_KEY
: Zerodha app's TOTP secret. When you enable TOTP, in kite website's settings.. it shows you a QR code that you scan with your authenticator app like google authenticator. below that qr code there is a link where if you click it'll give you a key that might look like MSMMH3G44BS42MI34WOKHVDBLRRXULDW.
This is your TOTP_KEY.
final .env
file content should look similar to this:
API_KEY="2jjerkdihur6m3j4"
USERID="WY3242"
PASSWORD="hellokitty123"
TOTP_KEY="MSMMH3G44BS42MI34WOKHVDBLRRXULDW"
After you are done filling in the values in .env file, run the following commands in order:
- to install dependencies
yarn
- to build app
yarn build
- to start (change
[PATH_TO_PROJECT_FOLDER]
to the folder's absolute address in your system)
node [PATH_TO_PROJECT_FOLDER]/build/main/index.js
- go to zerodha app connect login page
- wait for it to redirect to kite login page
- fill in username and password and submit
- wait for it to show totp input
- genertate totp using users zerodha totp secret key
- fill in totp and submit
- wait for zerodha to redirect to the apps redirect url
- done