Request Token
This guide documents the implementation of the Request Token step in an OAuth 1.0a flow customized for the Interactive Brokers (IBKR) Web API. Unlike standard OAuth 1.0a implementations that typically use HMAC-SHA1 for signing, this implementation uses RSA-SHA256 asymmetric signing, which is required by IBKR’s authentication model.
This is the first of three OAuth 1.0a steps in the IBKR flow:
- Request Token (documented here)
- Authorize Token (user consent, typically out-of-band)
- Access Token / Live Session Token exchange
Build the Signature Base String
The OAuth 1.0a signature base string follows the format:
Implementation details:
- Parameters are sorted alphabetically by key.
- The parameter string is constructed as
key=valuepairs joined by&before encoding — note this is a raw concatenation, not URL-encoded key/value pairs individually. - The entire parameter string is then percent-encoded using
quote(). - The URL is percent-encoded using
quote_plus(). - The three components are joined with literal
&characters.
Note regarding the NONCE value: Standard OAuth 1.0a specifies that each key and value should be individually percent-encoded before being joined, and that reserved characters use %20-style encoding (via quote(), not quote_plus()). This implementation encodes the URL with quote_plus() (which encodes spaces as +) and the joined parameter string with quote(). Confirm this matches IBKR’s server-side expectations — inconsistent encoding is the most common source of signature validation failures. Do not deviate from this pattern without testing against IBKR’s endpoint, as it has been validated against their implementation.
Sign the Base String with RSA-SHA256
Process:
- Encode the base string to UTF-8 bytes.
- Compute the SHA-256 digest.
- Sign the digest using PKCS#1 v1.5 padding with your RSA private key (
signature_key— aCrypto.PublicKey.RSAkey object). - Base64-encode the raw signature bytes into a transmittable string.
Finalize and Encode the Signature
The Base64 signature is percent-encoded (quote_plus) before insertion into the OAuth parameter set, since it may contain characters (+, /, =) that are invalid in HTTP header values.
The realm parameter is added at this stage — it is not part of the signature base string but is included in the final Authorization header, per OAuth 1.0a convention for realm scoping.
Construct the Authorization Header
The header follows the standard OAuth scheme format:
Parameters are sorted alphabetically (matching convention, though not strictly required at this stage since the signature was already computed).
User-Agent Note: IBKR’s API gateway may enforce User-Agent validation. Update this value to reflect your actual runtime/client rather than hardcoding "python/3.11" for production deployments — pin it to your actual interpreter/environment version, or set a custom identifying string as permitted by IBKR’s integration guidelines.

