Create a separate method for extracting username
This commit is contained in:
parent
e77e0f9e35
commit
aa8adfee4b
|
@ -204,8 +204,9 @@ class _Network:
|
||||||
# Load session_key and username from authentication token if provided
|
# Load session_key and username from authentication token if provided
|
||||||
if token and not self.session_key:
|
if token and not self.session_key:
|
||||||
sk_gen = SessionKeyGenerator(self)
|
sk_gen = SessionKeyGenerator(self)
|
||||||
self.session_key, self.username = \
|
self.session_key, self.username = sk_gen.get_web_auth_session_key_and_username(
|
||||||
sk_gen.get_web_auth_session_key(url=None, token=token)
|
url=None, token=token
|
||||||
|
)
|
||||||
|
|
||||||
# Generate a session_key if necessary
|
# Generate a session_key if necessary
|
||||||
if (
|
if (
|
||||||
|
@ -989,7 +990,7 @@ class SessionKeyGenerator:
|
||||||
b. sg = SessionKeyGenerator(network)
|
b. sg = SessionKeyGenerator(network)
|
||||||
c. url = sg.get_web_auth_url()
|
c. url = sg.get_web_auth_url()
|
||||||
d. Ask the user to open the URL and authorize you, and wait for it.
|
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:
|
2) Username and Password Authentication:
|
||||||
a. network = get_*_network(API_KEY, API_SECRET)
|
a. network = get_*_network(API_KEY, API_SECRET)
|
||||||
b. username = raw_input("Please enter your username: ")
|
b. username = raw_input("Please enter your username: ")
|
||||||
|
@ -1044,9 +1045,9 @@ class SessionKeyGenerator:
|
||||||
|
|
||||||
return url
|
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():
|
if url in self.web_auth_tokens.keys():
|
||||||
|
@ -1067,6 +1068,13 @@ class SessionKeyGenerator:
|
||||||
username = doc.getElementsByTagName("name")[0].firstChild.data
|
username = doc.getElementsByTagName("name")[0].firstChild.data
|
||||||
return session_key, username
|
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):
|
def get_session_key(self, username, password_hash):
|
||||||
"""
|
"""
|
||||||
Retrieve a session key with a username and a md5 hash of the user's
|
Retrieve a session key with a username and a md5 hash of the user's
|
||||||
|
|
Loading…
Reference in a new issue