I am using requests-oauthlib
to authenticate with the ETrade API. It requires the authorization URL to have the following format:
https://us.etrade.com/e/t/etws/authorize?key={oauth_consumer_key}&token={oauth_token}
However, when I call authorization_url()
, it uses oauth_token
instead of token
for that parameter. Currently I am using format()
to format the URL myself, but now I have both token
and oauth_token
parameters. This works, but is completely inelegant. Is there some way to modify the behavior of authorization_url()
to allow the URL format I require?
For completeness, here is my code:
oauth_session = requests_oauthlib.OAuth1Session(config.oauth_consumer_key, config.consumer_secret, callback_uri='oob')
def get_request_token():
path = 'oauth/request_token'
url = base_url + path
return oauth_session.fetch_request_token(url)
def get_authorization_url(request_token):
url_format = 'https://us.etrade.com/e/t/etws/authorize?key={oauth_consumer_key}&token={oauth_token}'
url = url_format.format(oauth_consumer_key=config.oauth_consumer_key, oauth_token=request_token['oauth_token'])
return oauth_session.authorization_url(url)
request_token = get_request_token()
print(get_authorization_url(request_token))