コード例 #1
0
ファイル: twitter.py プロジェクト: Macodom/django-connected
        if profile_image_url:
            # Hmm, hack to get our hands on the large image.  Not
            # really documented, but seems to work.
            avatar_url = profile_image_url.replace('_normal', '')
        return avatar_url

    def to_str(self):
        screen_name = self.get_screen_name()
        return '@%s' % screen_name if screen_name else super(TwitterAccount, self).to_str()

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(username=data.get('screen_name'),
                    name=data.get('name'))


class TwitterProvider(OAuthProvider):
    id = 'twitter'
    name = _('Twitter')
    account_class = TwitterAccount

    authorization_url = 'https://api.twitter.com/oauth/authenticate'
    access_token_url = 'https://api.twitter.com/oauth/access_token'
    request_token_url = 'https://api.twitter.com/oauth/request_token'
    profile_url = 'https://api.twitter.com/1.1/account/verify_credentials.json'

    consumer_key = settings.CONNECTED_ACCOUNTS_TWITTER_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_TWITTER_CONSUMER_SECRET

providers.register(TwitterProvider)
コード例 #2
0
    expires_in_key = ''

    authorization_url = 'https://login.mailchimp.com/oauth2/authorize'
    access_token_url = 'https://login.mailchimp.com/oauth2/token'
    profile_url = 'https://login.mailchimp.com/oauth2/metadata'

    consumer_key = settings.CONNECTED_ACCOUNTS_MAILCHIMP_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_MAILCHIMP_CONSUMER_SECRET

    def extract_uid(self, data):
        """Return unique identifier from the profile info."""
        return data.get('user_id', None)

    def get_profile_data(self, raw_token):
        """Fetch user profile information."""
        token_data = json.loads(raw_token)
        # This header is the 'magic' that makes this empty GET request work.
        headers = {'Authorization': 'OAuth %s' % token_data['access_token']}

        try:
            response = self.request('get', self.profile_url, headers=headers)
            response.raise_for_status()
        except RequestException as e:
            logger.error('Unable to fetch user profile: {0}'.format(e))
            return None
        else:
            return response.json() or response.text


providers.register(MailChimpProvider)
コード例 #3
0
            # Hmm, hack to get our hands on the large image.  Not
            # really documented, but seems to work.
            avatar_url = profile_image_url.replace('_normal', '')
        return avatar_url

    def to_str(self):
        screen_name = self.get_screen_name()
        return '@%s' % screen_name if screen_name else super(
            TwitterAccount, self).to_str()

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(username=data.get('screen_name'), name=data.get('name'))


class TwitterProvider(OAuthProvider):
    id = 'twitter'
    name = _('Twitter')
    account_class = TwitterAccount

    authorization_url = 'https://api.twitter.com/oauth/authenticate'
    access_token_url = 'https://api.twitter.com/oauth/access_token'
    request_token_url = 'https://api.twitter.com/oauth/request_token'
    profile_url = 'https://api.twitter.com/1.1/account/verify_credentials.json'

    consumer_key = settings.CONNECTED_ACCOUNTS_TWITTER_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_TWITTER_CONSUMER_SECRET


providers.register(TwitterProvider)
コード例 #4
0
ファイル: google.py プロジェクト: Macodom/django-connected
    def get_avatar_url(self):
        return self.account.extra_data.get('picture')

    def to_str(self):
        default = super(GoogleAccount, self).to_str()
        return self.account.extra_data.get('name', default)

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(email=data.get('email'),
                    last_name=data.get('family_name'),
                    first_name=data.get('given_name'))


class GoogleProvider(OAuth2Provider):
    id = 'google'
    name = _('Google+')
    account_class = GoogleAccount

    authorization_url = 'https://accounts.google.com/o/oauth2/auth'
    access_token_url = 'https://accounts.google.com/o/oauth2/token'
    profile_url = 'https://www.googleapis.com/oauth2/v1/userinfo'

    consumer_key = settings.CONNECTED_ACCOUNTS_GOOGLE_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_GOOGLE_CONSUMER_SECRET
    scope = settings.CONNECTED_ACCOUNTS_GOOGLE_SCOPE
    auth_params = settings.CONNECTED_ACCOUNTS_GOOGLE_AUTH_PARAMS


providers.register(GoogleProvider)
コード例 #5
0
ファイル: facebook.py プロジェクト: Macodom/django-connected
        return 'https://graph.facebook.com/v2.3/%s/picture' \
               '?type=square&height=600&width=600&return_ssl_resources=1' % uid  # noqa

    def to_str(self):
        default = super(FacebookAccount, self).to_str()
        return self.account.extra_data.get('name', default)

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(email=data.get('email'),
                    first_name=data.get('first_name'),
                    last_name=data.get('last_name'))


class FacebookProvider(OAuth2Provider):
    id = 'facebook'
    name = _('Facebook')
    account_class = FacebookAccount
    expires_in_key = 'expires'

    authorization_url = 'https://www.facebook.com/dialog/oauth'
    access_token_url = 'https://graph.facebook.com/oauth/access_token'
    profile_url = 'https://graph.facebook.com/me'

    consumer_key = settings.CONNECTED_ACCOUNTS_FACEBOOK_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_FACEBOOK_CONSUMER_SECRET
    scope = settings.CONNECTED_ACCOUNTS_FACEBOOK_SCOPE
    auth_params = settings.CONNECTED_ACCOUNTS_FACEBOOK_AUTH_PARAMS

providers.register(FacebookProvider)
コード例 #6
0
ファイル: facebook.py プロジェクト: rage2000/django-connected
               '?type=square&height=600&width=600&return_ssl_resources=1' % uid  # noqa

    def to_str(self):
        default = super(FacebookAccount, self).to_str()
        return self.account.extra_data.get('name', default)

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(email=data.get('email'),
                    first_name=data.get('first_name'),
                    last_name=data.get('last_name'))


class FacebookProvider(OAuth2Provider):
    id = 'facebook'
    name = _('Facebook')
    account_class = FacebookAccount
    expires_in_key = 'expires'

    authorization_url = 'https://www.facebook.com/dialog/oauth'
    access_token_url = 'https://graph.facebook.com/oauth/access_token'
    profile_url = 'https://graph.facebook.com/me'

    consumer_key = settings.CONNECTED_ACCOUNTS_FACEBOOK_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_FACEBOOK_CONSUMER_SECRET
    scope = settings.CONNECTED_ACCOUNTS_FACEBOOK_SCOPE
    auth_params = settings.CONNECTED_ACCOUNTS_FACEBOOK_AUTH_PARAMS


providers.register(FacebookProvider)
コード例 #7
0
    def to_str(self):
        default = super(BitlyAccount, self).to_str()
        return self.account.extra_data.get('full_name', default)

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(username=data['login'], name=data.get('full_name'))


class BitlyProvider(OAuth2Provider):
    id = 'bitly'
    name = _('Bitly')
    account_class = BitlyAccount

    access_token_url = 'https://api-ssl.bitly.com/oauth/access_token'
    authorization_url = 'https://bitly.com/oauth/authorize'
    profile_url = 'https://api-ssl.bitly.com/v3/user/info'

    consumer_key = settings.CONNECTED_ACCOUNTS_BITLY_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_BITLY_CONSUMER_SECRET

    def extract_uid(self, data):
        return str(data['data']['login'])

    def extract_extra_data(self, data):
        return data.get('data', {})


providers.register(BitlyProvider)
コード例 #8
0
ファイル: disqus.py プロジェクト: rage2000/django-connected
    consumer_key = settings.CONNECTED_ACCOUNTS_DISQUS_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_DISQUS_CONSUMER_SECRET
    scope = settings.CONNECTED_ACCOUNTS_DISQUS_SCOPE

    def get_profile_data(self, raw_token):
        """Fetch user profile information."""
        token_data = json.loads(raw_token)
        params = {
            'access_token': token_data['access_token'],
            'api_key': self.consumer_key,
            'api_secret': token_data['access_token']
        }
        try:
            response = self.request('get', self.profile_url, params=params)
            response.raise_for_status()
        except RequestException as e:
            logger.error('Unable to fetch user profile: {0}'.format(e))
            return None
        else:
            return response.json() or response.text

    def extract_uid(self, data):
        """Return unique identifier from the profile info."""
        return str(data['response']['id'])

    def extract_extra_data(self, data):
        return data.get('response', {})

providers.register(DisqusProvider)
コード例 #9
0
        default = super(InstagramAccount, self).to_str()
        return self.account.extra_data.get('username', default)

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(username=data.get('username'),
                    name=data.get('full_name'))


class InstagramProvider(OAuth2Provider):
    id = 'instagram'
    name = _('Instagram')
    account_class = InstagramAccount

    access_token_url = 'https://api.instagram.com/oauth/access_token'
    authorization_url = 'https://api.instagram.com/oauth/authorize'
    profile_url = 'https://api.instagram.com/v1/users/self'

    consumer_key = settings.CONNECTED_ACCOUNTS_INSTAGRAM_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_INSTAGRAM_CONSUMER_SECRET
    scope = settings.CONNECTED_ACCOUNTS_INSTAGRAM_SCOPE

    def extract_uid(self, data):
        return str(data['data']['id'])

    def extract_extra_data(self, data):
        return data.get('data', {})


providers.register(InstagramProvider)
コード例 #10
0
ファイル: bitly.py プロジェクト: Macodom/django-connected
    def to_str(self):
        default = super(BitlyAccount, self).to_str()
        return self.account.extra_data.get('full_name', default)

    def extract_common_fields(self):
        data = self.account.extra_data
        return dict(username=data['login'],
                    name=data.get('full_name'))


class BitlyProvider(OAuth2Provider):
    id = 'bitly'
    name = _('Bitly')
    account_class = BitlyAccount

    access_token_url = 'https://api-ssl.bitly.com/oauth/access_token'
    authorization_url = 'https://bitly.com/oauth/authorize'
    profile_url = 'https://api-ssl.bitly.com/v3/user/info'

    consumer_key = settings.CONNECTED_ACCOUNTS_BITLY_CONSUMER_KEY
    consumer_secret = settings.CONNECTED_ACCOUNTS_BITLY_CONSUMER_SECRET

    def extract_uid(self, data):
        return str(data['data']['login'])

    def extract_extra_data(self, data):
        return data.get('data', {})

providers.register(BitlyProvider)