Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract username from session #291

Merged
merged 4 commits into from
Jan 6, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Extract username from session
  • Loading branch information
jacebrowning committed Jan 5, 2019
commit e77e0f9e35c04443d70045ff3bf3d42533b04525
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