I would like to authenticate against the Etrade API using Go and Postman. I am following the official Etrade API Developer Docs:
I successfully completed the Oauth 1.0 flow using the Python example they provided (with some slight modifications to print some of the session attributes):
$ python3 etrade_python_client.py
1) Sandbox Consumer Key
2) Live Consumer Key
3) Exit
Please select Consumer Key Type: 2
Please accept agreement and enter verification code from browser: REDACTED
access_token_response: <Response [200]>
access_token: REDACTED
access_token_secret: REDACTED
But I have had no success authenticating using the Go or Postman implementations of Oauth 1.0. For Go, I wrote this sample client using the dghubble/oauth1 library, and for Postman I am using the built-in auth tool.
My trouble is largely with generating the correct oauth_signature
in each of these. I always get this error:
Or if I try to plug-and-play the access token I obtained from Etrade's sample Python client into Postman when, for instance, accessing the /accounts/list
API endpoint, the response I receive is:
<Error>
<message>oauth_problem=signature_invalid</message>
</Error>
It's strange that their Python example (which uses rauth) has a different behavior than Go or Postman. Seems that Etrade does something non-standard that fits the requests.Session
shape of the rauth
implementation. Is there a way to know if I'm generating my signatures correctly for any implementation I use?
Appendix:
Sample Postman requests:
Capture of session attributes when using Python rauth
library (sensitive info redacted):
https://gist.github.com/natemurthy/a7f628e44da9651d0676291803915c9c
Comparison of HTTP headers when calling /v1/accounts/list
between Python vs Go:
Python:
GET https://api.etrade.com/v1/accounts/list.json
{'Authorization': 'OAuth realm="",oauth_consumer_key=REDACTED",oauth_nonce="22d0b83e4cba610148c990fdab1c327948a10677",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1668988571",oauth_token="REDACTED",oauth_version="1.0",oauth_signature="REDACTED"'}
Response: 200 OK
Go:
GET https://api.etrade.com/v1/accounts/list.json
map[Authorization:[OAuth oauth_consumer_key="REDACTED", oauth_nonce="eZ1twhwIs7f3wD90uOelpuNNAE2RZ8wkQm4gEKvlklM%3D", oauth_signature="REDACTED", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1669074040", oauth_token="REDACTED", oauth_version="1.0"]]
Response: 401 Unauthorized
{"Error":{"message":"oauth_problem=signature_invalid"}}