3
from ..utils import handle_http_errors
4
from .base import BaseAuth
7
class LastFmAuth(BaseAuth):
9
Last.Fm authentication backend. Requires two settings:
10
SOCIAL_AUTH_LASTFM_KEY
11
SOCIAL_AUTH_LASTFM_SECRET
13
Don't forget to set the Last.fm callback to something sensible like
14
http://your.site/lastfm/complete
17
AUTH_URL = 'http://www.last.fm/api/auth/?api_key={api_key}'
19
('key', 'session_key')
23
return self.AUTH_URL.format(api_key=self.setting('KEY'))
26
def auth_complete(self, *args, **kwargs):
27
"""Completes login process, must return user instance"""
28
key, secret = self.get_key_and_secret()
29
token = self.data['token']
31
signature = hashlib.md5(''.join(
32
('api_key', key, 'methodauth.getSession', 'token', token, secret)
33
).encode()).hexdigest()
35
response = self.get_json('http://ws.audioscrobbler.com/2.0/', data={
36
'method': 'auth.getSession',
43
kwargs.update({'response': response['session'], 'backend': self})
44
return self.strategy.authenticate(*args, **kwargs)
46
def get_user_id(self, details, response):
47
"""Return a unique ID for the current user, by default from server
49
return response.get('name')
51
def get_user_details(self, response):
52
fullname, first_name, last_name = self.get_user_names(response['name'])
54
'username': response['name'],
57
'first_name': first_name,
58
'last_name': last_name