Extract username from session

This commit is contained in:
Jace Browning 2019-01-05 13:18:06 -05:00
parent 6134945df7
commit e77e0f9e35

View file

@ -201,10 +201,11 @@ class _Network:
self.last_call_time = 0
self.limit_rate = False
# Load session_key from authentication token if provided
# Load session_key and username from authentication token if provided
if token and not self.session_key:
sk_gen = SessionKeyGenerator(self)
self.session_key = sk_gen.get_web_auth_session_key(url=None, token=token)
self.session_key, self.username = \
sk_gen.get_web_auth_session_key(url=None, token=token)
# Generate a session_key if necessary
if (
@ -988,7 +989,7 @@ class SessionKeyGenerator:
b. sg = SessionKeyGenerator(network)
c. url = sg.get_web_auth_url()
d. Ask the user to open the URL and authorize you, and wait for it.
e. session_key = sg.get_web_auth_session_key(url)
e. session_key, username = sg.get_web_auth_session_key(url)
2) Username and Password Authentication:
a. network = get_*_network(API_KEY, API_SECRET)
b. username = raw_input("Please enter your username: ")
@ -1062,7 +1063,9 @@ class SessionKeyGenerator:
doc = request.execute()
return doc.getElementsByTagName("key")[0].firstChild.data
session_key = doc.getElementsByTagName("key")[0].firstChild.data
username = doc.getElementsByTagName("name")[0].firstChild.data
return session_key, username
def get_session_key(self, username, password_hash):
"""