fix: initialize gateway brokerage session with browser cookies#43
Merged
NitayRabi merged 1 commit intoMay 12, 2026
Merged
Conversation
NitayRabi
reviewed
May 12, 2026
Contributor
NitayRabi
left a comment
There was a problem hiding this comment.
Thanks for the contribution! This improves the reliability of the REST session initialization significantly. Merging now.
Contributor
|
Thanks for the contribution! This improves the reliability of the REST session initialization significantly. Merging now. |
|
🎉 This PR is included in version 1.21.9 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes Client Portal Gateway authentication completion more reliable after browser/headless login.
It addresses a case where the Gateway page reports
Client login succeeds, but REST endpoints such as/iserver/auth/statuscan remainauthenticated: falseunless the REST brokerage session is initialized using the browser-established Gateway cookies and the full brokerage-session sequence.Changes:
IBClient.IBClient.setSessionCookies(...)and attach the captured cookies to raw Gateway REST requests./sso/validate,/iserver/auth/statusto deriveMAC/hardware_info,/iserver/auth/ssodh/init,/iserver/reauthenticate,/tickle,/portfolio/accounts,/iserver/auth/statusbecomes authenticated.Client login succeedsas browser-login success only; do not return auth success until the REST brokerage session is actually initialized.initializeBrokerageSession()from browser-auth polling when available, with a backwards-compatible fallback to the previouscheckAuthenticationStatus()+reauthenticate()path.IB_PAPER_TRADINGinto headless auth config so the paper/live selection is preserved./ticklesession maintenance.Why
In some Gateway sessions, successful browser login does not immediately make the Client Portal REST session usable. The UI can show
Client login succeedswhile REST still returnsauthenticated: false.In that state, simply calling
/iserver/reauthenticateor checking/iserver/auth/statusis not always sufficient. The working sequence needs the Gateway/browser cookie context and the brokerage-session initialization endpoints to be exercised before the MCP server declares authentication complete.This prevents false-positive authentication success where downstream account/positions/orders tools still fail because the REST brokerage session was not fully established.