Skip to content

Commit

Permalink
Extract username from session
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Jan 5, 2019
1 parent 6134945 commit e77e0f9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pylast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ def __init__(
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 (
Expand Down Expand Up @@ -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: ")
Expand Down Expand Up @@ -1062,7 +1063,9 @@ def get_web_auth_session_key(self, url, token=""):

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):
"""
Expand Down

0 comments on commit e77e0f9

Please sign in to comment.