2
Mail.ru OAuth2 backend, docs at:
3
https://python-social-auth.readthedocs.io/en/latest/backends/mailru.html
5
from hashlib import md5
7
from six.moves.urllib_parse import unquote
9
from .oauth import BaseOAuth2
12
class MailruOAuth2(BaseOAuth2):
13
"""Mail.ru authentication backend"""
14
name = 'mailru-oauth2'
16
AUTHORIZATION_URL = 'https://connect.mail.ru/oauth/authorize'
17
ACCESS_TOKEN_URL = 'https://connect.mail.ru/oauth/token'
18
ACCESS_TOKEN_METHOD = 'POST'
19
EXTRA_DATA = [('refresh_token', 'refresh_token'),
20
('expires_in', 'expires')]
22
def get_user_details(self, response):
23
"""Return user details from Mail.ru request"""
24
fullname, first_name, last_name = self.get_user_names(
25
first_name=unquote(response['first_name']),
26
last_name=unquote(response['last_name'])
28
return {'username': unquote(response['nick']),
29
'email': unquote(response['email']),
31
'first_name': first_name,
32
'last_name': last_name}
34
def user_data(self, access_token, *args, **kwargs):
35
"""Return user data from Mail.ru REST API"""
36
key, secret = self.get_key_and_secret()
37
data = {'method': 'users.getInfo',
38
'session_key': access_token,
41
param_list = sorted(list(item + '=' + data[item] for item in data))
43
(''.join(param_list) + secret).encode('utf-8')
45
return self.get_json('http://www.appsmail.ru/platform/api',