/usr/lib/python2.7/dist-packages/social/backends/fitbit.py is in python-social-auth 1:0.2.21+dfsg-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 | """
Fitbit OAuth backend, docs at:
http://psa.matiasaguirre.net/docs/backends/fitbit.html
"""
import base64
from social.backends.oauth import BaseOAuth1, BaseOAuth2
class FitbitOAuth1(BaseOAuth1):
"""Fitbit OAuth1 authentication backend"""
name = 'fitbit'
AUTHORIZATION_URL = 'https://www.fitbit.com/oauth/authorize'
REQUEST_TOKEN_URL = 'https://api.fitbit.com/oauth/request_token'
ACCESS_TOKEN_URL = 'https://api.fitbit.com/oauth/access_token'
ID_KEY = 'encodedId'
EXTRA_DATA = [('encodedId', 'id'),
('displayName', 'username')]
def get_user_details(self, response):
"""Return user details from Fitbit account"""
return {'username': response.get('displayName'),
'email': ''}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json(
'https://api.fitbit.com/1/user/-/profile.json',
auth=self.oauth_auth(access_token)
)['user']
class FitbitOAuth2(BaseOAuth2):
"""Fitbit OAuth2 authentication backend"""
name = 'fitbit'
AUTHORIZATION_URL = 'https://www.fitbit.com/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://api.fitbit.com/oauth2/token'
ACCESS_TOKEN_METHOD = 'POST'
REFRESH_TOKEN_URL = 'https://api.fitbit.com/oauth2/token'
DEFAULT_SCOPE = ['profile']
ID_KEY = 'encodedId'
REDIRECT_STATE = False
EXTRA_DATA = [('expires_in', 'expires'),
('refresh_token', 'refresh_token', True),
('encodedId', 'id'),
('displayName', 'username')]
def get_user_details(self, response):
"""Return user details from Fitbit account"""
return {'username': response.get('displayName'),
'email': ''}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
auth_header = {"Authorization": "Bearer %s" % access_token}
return self.get_json(
'https://api.fitbit.com/1/user/-/profile.json',
headers=auth_header
)['user']
def auth_headers(self):
return {
'Authorization': 'Basic {0}'.format(base64.urlsafe_b64encode(
('{0}:{1}'.format(*self.get_key_and_secret()).encode())
))
}
|