Kite Connect uses a two-step OAuth flow to authenticate users. In the first step, you redirect the user to Zerodha’s login page. After a successful login, Zerodha redirects back to your app with a short-livedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/anurag-roy/kiteconnect-ts/llms.txt
Use this file to discover all available pages before exploring further.
request_token. In the second step, your server exchanges that request_token — along with your api_secret — for a long-lived access_token that you use for all subsequent API calls.
The login flow
Generate the login URL
Call
getLoginURL() to get the URL you should redirect the user to. The URL includes your api_key and the API version as query parameters.Receive the request_token
After the user logs in, Zerodha redirects them to your registered redirect URL with a Extract the
request_token in the query string:request_token from the query parameters on your server before proceeding.Exchange for an access_token
Call
generateSession() with the request_token and your api_secret. This call computes an SHA-256 checksum of api_key + request_token + api_secret and posts it to the Kite Connect token endpoint. On success it returns a SessionData object containing the access_token and sets the token on the kc instance automatically.Persisting and reusing the access token
After your first successfulgenerateSession() call, save the access_token in a database or server-side session. On subsequent requests — after the token has been persisted — initialize KiteConnect with both the api_key and the stored access_token, or call setAccessToken() explicitly.
Store the
access_token in a secure location such as a database row tied to the user’s session, an encrypted server-side cookie, or a secrets manager. Never store it in localStorage or expose it to the browser.Handling session expiry
Rather than catchingTokenException errors on every API call, register a session expiry hook once. When the Kite Connect API returns a TokenException (token expired, invalidated, or revoked), the client calls your hook automatically.
Invalidating the access token (logout)
CallinvalidateAccessToken() to revoke the current session. Pass an explicit token to invalidate a specific one, or call it without arguments to invalidate the token currently set on the instance.
Renewing the access token
If your Kite Connect app has been granted arefresh_token (available to certain approved platforms), you can obtain a new access_token without repeating the full login flow.
Validating postback webhooks
When Zerodha sends order update postbacks (webhooks) to your server, usevalidatePostback() to verify the checksum and confirm the payload is authentic. Pass the raw postback object and your api_secret.
The checksum is computed as
SHA-256(order_id + order_timestamp + api_secret). If the computed checksum does not match the one in the payload, validatePostback() returns false. If required fields are missing, it throws an error.