Skip to content

Commit

Permalink
Merge pull request #20 from timkpaine/temp
Browse files Browse the repository at this point in the history
Update authentication
  • Loading branch information
timkpaine committed Jul 6, 2019
2 parents 3e9357a + bee8f16 commit 65bb614
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tdameritrade/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import urllib.parse as up


def authentication(client_id, redirect_uri):
def authentication(client_id, redirect_uri, tdauser=None, tdapass=None):
client_id = client_id + '@AMER.OAUTHAP'
url = 'https://auth.tdameritrade.com/auth?response_type=code&redirect_uri=' + up.quote(redirect_uri) + '&client_id=' + up.quote(client_id)

Expand Down Expand Up @@ -36,13 +36,16 @@ def authentication(client_id, redirect_uri):

driver.get(url)

# Setting TDAUSER and TDAPASS environment variables enables
# fully automated oauth2 authentication
if 'TDAUSER' in os.environ and 'TDAPASS' in os.environ:
# Set tdauser and tdapass from environemnt if TDAUSER and TDAPASS environment variables were defined
tdauser = tdauser or os.environ.get('TDAUSER', '')
tdapass = tdapass or os.environ.get('TDAPASS', '')

# Fully automated oauth2 authentication (if tdauser and tdapass were intputed into the function, or found as environment variables)
if tdauser and tdapass:
ubox = driver.find_element_by_id('username')
pbox = driver.find_element_by_id('password')
ubox.send_keys(os.environ['TDAUSER'])
pbox.send_keys(os.environ['TDAPASS'])
ubox.send_keys(tdauser)
pbox.send_keys(tdapass)
driver.find_element_by_id('accept').click()

driver.find_element_by_id('accept').click()
Expand Down

0 comments on commit 65bb614

Please sign in to comment.