Create a separate method for extracting username

This commit is contained in:
Jace Browning 2019-01-05 16:00:46 -05:00
parent e77e0f9e35
commit aa8adfee4b

View file

@ -204,8 +204,9 @@ class _Network:
# Load session_key and username from authentication token if provided
if token and not self.session_key:
sk_gen = SessionKeyGenerator(self)
self.session_key, self.username = \
sk_gen.get_web_auth_session_key(url=None, token=token)
self.session_key, self.username = sk_gen.get_web_auth_session_key_and_username(
url=None, token=token
)
# Generate a session_key if necessary
if (
@ -989,7 +990,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, username = sg.get_web_auth_session_key(url)
e. session_key = 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: ")
@ -1044,9 +1045,9 @@ class SessionKeyGenerator:
return url
def get_web_auth_session_key(self, url, token=""):
def get_web_auth_session_key_and_username(self, url, token=""):
"""
Retrieves the session key of a web authorization process by its URL.
Retrieves the session key and username of a web authorization process by its URL.
"""
if url in self.web_auth_tokens.keys():
@ -1067,6 +1068,13 @@ class SessionKeyGenerator:
username = doc.getElementsByTagName("name")[0].firstChild.data
return session_key, username
def get_web_auth_session_key(self, url, token=""):
"""
Retrieves the session key of a web authorization process by its URL.
"""
session_key, _username = self.get_web_auth_session_key_and_username(url, token)
return session_key
def get_session_key(self, username, password_hash):
"""
Retrieve a session key with a username and a md5 hash of the user's