class Facebook(PlatformOAuth2): # Platform attributes name = 'facebook' display_name = 'Facebook' account_url = 'https://www.facebook.com/profile.php?id={user_id}' optional_user_name = True # Auth attributes auth_url = 'https://www.facebook.com/dialog/oauth' access_token_url = 'https://graph.facebook.com/oauth/access_token' oauth_default_scope = ['public_profile,email,user_friends'] # API attributes api_format = 'json' api_paginator = keys_paginator('data', paging='paging', prev='previous') api_url = 'https://graph.facebook.com' api_user_name_info_path = '/{user_name}' api_user_self_info_path = '/me' api_friends_path = '/v2.2/{user_id}/friends' api_friends_limited = True # User info extractors x_user_id = key('id') x_user_name = key('username') x_display_name = key('name') x_email = key('email') def x_avatar_url(self, extracted, info, default): return 'https://graph.facebook.com/' + extracted.user_id + '/picture?width=256&height=256'
class Facebook(PlatformOAuth2): # Platform attributes name = 'facebook' display_name = 'Facebook' fontawesome_name = 'facebook-square' account_url = 'https://www.facebook.com/app_scoped_user_id/{user_id}/' optional_user_name = True # Auth attributes auth_url = 'https://www.facebook.com/v2.10/dialog/oauth' access_token_url = 'https://graph.facebook.com/v2.10/oauth/access_token' refresh_token_url = None oauth_default_scope = ['public_profile'] oauth_email_scope = 'email' oauth_friends_scope = 'user_friends' # API attributes api_format = 'json' api_paginator = keys_paginator('data', paging='paging', prev='previous') api_url = 'https://graph.facebook.com/v2.10' api_user_self_info_path = '/me?fields=id,name,email' api_friends_path = '/me/friends' api_friends_limited = True # User info extractors x_user_id = key('id') x_display_name = key('name') x_email = key('email') x_description = key('bio') def x_avatar_url(self, extracted, info, default): return 'https://graph.facebook.com/' + extracted.user_id + '/picture?width=256&height=256'
class Bitbucket(PlatformOAuth1): # Platform attributes name = 'bitbucket' display_name = 'Bitbucket' fontawesome_name = name account_url = 'https://bitbucket.org/{user_name}' # Auth attributes auth_url = 'https://bitbucket.org/api/1.0' authorize_path = '/oauth/authenticate' # API attributes api_format = 'json' api_paginator = keys_paginator('values', prev='previous', total='size') api_url = 'https://bitbucket.org/api' api_user_info_path = '/2.0/users/{user_id}' api_user_name_info_path = '/2.0/users/{user_name}' api_user_self_info_path = '/2.0/user' api_team_members_path = '/2.0/teams/{user_name}/members' api_friends_path = '/2.0/users/{user_name}/following' # User info extractors x_user_info = key('user') x_user_id = key('uuid') x_user_name = key('username') x_display_name = key('display_name') x_email = not_available x_avatar_url = any_key('avatar', ('links', 'avatar', 'href')) x_is_team = key('type', lambda v: v == 'team') def api_get(self, domain, path, sess=None, **kw): """Extend to manually retry /users/pypy as /teams/pypy. Bitbucket gives us a 404 where a 30x would be more helpful. """ try: return PlatformOAuth1.api_get(self, domain, path, sess, **kw) except Response as response: if response.code == 404 and ' is a team account' in response.body: assert path.startswith('/2.0/users/') path = '/2.0/teams/' + path[11:] return PlatformOAuth1.api_get(self, domain, path, sess, **kw) else: raise