/usr/lib/python3/dist-packages/social/backends/beats.py is in python3-social-auth 0.2.13-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """
Beats backend, docs at:
https://developer.beatsmusic.com/docs
"""
import base64
from social.utils import handle_http_errors
from social.backends.oauth import BaseOAuth2
class BeatsOAuth2(BaseOAuth2):
name = 'beats'
SCOPE_SEPARATOR = ' '
ID_KEY = 'user_context'
AUTHORIZATION_URL = \
'https://partner.api.beatsmusic.com/v1/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://partner.api.beatsmusic.com/oauth2/token'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False
def get_user_id(self, details, response):
return response['result'][BeatsOAuth2.ID_KEY]
def auth_headers(self):
return {
'Authorization': 'Basic {0}'.format(base64.urlsafe_b64encode(
('{0}:{1}'.format(*self.get_key_and_secret()).encode())
))
}
@handle_http_errors
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
self.process_error(self.data)
response = self.request_access_token(
self.ACCESS_TOKEN_URL,
data=self.auth_complete_params(self.validate_state()),
headers=self.auth_headers(),
method=self.ACCESS_TOKEN_METHOD
)
self.process_error(response)
# mashery wraps in jsonrpc
if response.get('jsonrpc', None):
response = response.get('result', None)
return self.do_auth(response['access_token'], response=response,
*args, **kwargs)
def get_user_details(self, response):
"""Return user details from Beats account"""
response = response['result']
fullname, first_name, last_name = self.get_user_names(
response.get('display_name')
)
return {'username': response.get('id'),
'email': response.get('email'),
'fullname': fullname,
'first_name': first_name,
'last_name': last_name}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json(
'https://partner.api.beatsmusic.com/v1/api/me',
headers={'Authorization': 'Bearer {0}'.format(access_token)}
)
|