コード例 #1
0
from datetime import datetime

from users.socialaccount import app_settings
from users.socialaccount.providers.oauth.views import (OAuthAdapter,
                                                       OAuthCallbackView,
                                                       OAuthLoginView)

from .provider import EvernoteProvider


class EvernoteOAuthAdapter(OAuthAdapter):
    provider_id = EvernoteProvider.id
    settings = app_settings.PROVIDERS.get(provider_id, {})
    request_token_url = 'https://%s/oauth' % (settings.get(
        'EVERNOTE_HOSTNAME', 'sandbox.evernote.com'))
    access_token_url = 'https://%s/oauth' % (settings.get(
        'EVERNOTE_HOSTNAME', 'sandbox.evernote.com'))
    authorize_url = 'https://%s/OAuth.action' % (settings.get(
        'EVERNOTE_HOSTNAME', 'sandbox.evernote.com'))

    def complete_login(self, request, app, token, response):
        token.expires_at = datetime.fromtimestamp(
            int(response['edam_expires']) / 1000.0)
        extra_data = response
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(EvernoteOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(EvernoteOAuthAdapter)
コード例 #2
0
    users_url = 'https://bitbucket.org/api/1.0/users/'

    def get_user_info(self):
        # TODO: Actually turn these into EmailAddress
        emails = json.loads(self.query(self.emails_url))
        for address in reversed(emails):
            if address['active']:
                email = address['email']
                if address['primary']:
                    break
        data = json.loads(self.query(self.users_url + email))
        user = data['user']
        return user


class BitbucketOAuthAdapter(OAuthAdapter):
    provider_id = BitbucketProvider.id
    request_token_url = 'https://bitbucket.org/api/1.0/oauth/request_token'
    access_token_url = 'https://bitbucket.org/api/1.0/oauth/access_token'
    authorize_url = 'https://bitbucket.org/api/1.0/oauth/authenticate'

    def complete_login(self, request, app, token, response):
        client = BitbucketAPI(request, app.client_id, app.secret,
                              self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)

oauth_login = OAuthLoginView.adapter_view(BitbucketOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(BitbucketOAuthAdapter)
コード例 #3
0
class TwitterAPI(OAuth):
    """
    Verifying twitter credentials
    """
    url = 'https://api.twitter.com/1.1/account/verify_credentials.json'

    def get_user_info(self):
        user = json.loads(self.query(self.url))
        return user


class TwitterOAuthAdapter(OAuthAdapter):
    provider_id = TwitterProvider.id
    request_token_url = 'https://api.twitter.com/oauth/request_token'
    access_token_url = 'https://api.twitter.com/oauth/access_token'
    # Issue #42 -- this one authenticates over and over again...
    # authorize_url = 'https://api.twitter.com/oauth/authorize'
    authorize_url = 'https://api.twitter.com/oauth/authenticate'

    def complete_login(self, request, app, token, response):
        client = TwitterAPI(request, app.client_id, app.secret,
                            self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(TwitterOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(TwitterOAuthAdapter)
コード例 #4
0
                                                       OAuthLoginView,
                                                       OAuthCallbackView)

from .provider import XingProvider


class XingAPI(OAuth):
    url = 'https://api.xing.com/v1/users/me.json'

    def get_user_info(self):
        user = json.loads(self.query(self.url))
        return user


class XingOAuthAdapter(OAuthAdapter):
    provider_id = XingProvider.id
    request_token_url = 'https://api.xing.com/v1/request_token'
    access_token_url = 'https://api.xing.com/v1/access_token'
    authorize_url = 'https://www.xing.com/v1/authorize'

    def complete_login(self, request, app, token, response):
        client = XingAPI(request, app.client_id, app.secret,
                         self.request_token_url)
        extra_data = client.get_user_info()['users'][0]
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(XingOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(XingOAuthAdapter)
コード例 #5
0
                                                         OAuthLoginView,
                                                         OAuthCallbackView)

from .provider import TumblrProvider


class TumblrAPI(OAuth):
    url = 'http://api.tumblr.com/v2/user/info'

    def get_user_info(self):
        data = json.loads(self.query(self.url))
        return data['response']['user']


class TumblrOAuthAdapter(OAuthAdapter):
    provider_id = TumblrProvider.id
    request_token_url = 'https://www.tumblr.com/oauth/request_token'
    access_token_url = 'https://www.tumblr.com/oauth/access_token'
    authorize_url = 'https://www.tumblr.com/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = TumblrAPI(request, app.client_id, app.secret,
                           self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth_login = OAuthLoginView.adapter_view(TumblrOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(TumblrOAuthAdapter)
コード例 #6
0
        children = list(xml)
        if not children:
            return xml.text
        else:
            out = {}
            for node in list(xml):
                if node.tag in out:
                    if not isinstance(out[node.tag], list):
                        out[node.tag] = [out[node.tag]]
                    out[node.tag].append(self.to_dict(node))
                else:
                    out[node.tag] = self.to_dict(node)
            return out


class LinkedInOAuthAdapter(OAuthAdapter):
    provider_id = LinkedInProvider.id
    request_token_url = 'https://api.linkedin.com/uas/oauth/requestToken'
    access_token_url = 'https://api.linkedin.com/uas/oauth/accessToken'
    authorize_url = 'https://www.linkedin.com/uas/oauth/authenticate'

    def complete_login(self, request, app, token, response):
        client = LinkedInAPI(request, app.client_id, app.secret,
                             self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)

oauth_login = OAuthLoginView.adapter_view(LinkedInOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(LinkedInOAuthAdapter)
コード例 #7
0
from .provider import DropboxProvider


class DropboxAPI(OAuth):
    """
    Verifying twitter credentials
    """
    url = 'https://api.dropbox.com/1/account/info'

    def get_user_info(self):
        user = json.loads(self.query(self.url))
        return user


class DropboxOAuthAdapter(OAuthAdapter):
    provider_id = DropboxProvider.id
    request_token_url = 'https://api.dropbox.com/1/oauth/request_token'
    access_token_url = 'https://api.dropbox.com/1/oauth/access_token'
    authorize_url = 'https://www.dropbox.com/1/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = DropboxAPI(request, app.client_id, app.secret,
                            self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(DropboxOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(DropboxOAuthAdapter)
コード例 #8
0
                                                       OAuthLoginView,
                                                       OAuthCallbackView)
from .provider import VimeoProvider


class VimeoAPI(OAuth):
    url = 'http://vimeo.com/api/rest/v2?method=vimeo.people.getInfo'

    def get_user_info(self):
        url = self.url
        data = json.loads(self.query(url, params=dict(format='json')))
        return data['person']


class VimeoOAuthAdapter(OAuthAdapter):
    provider_id = VimeoProvider.id
    request_token_url = 'https://vimeo.com/oauth/request_token'
    access_token_url = 'https://vimeo.com/oauth/access_token'
    authorize_url = 'https://vimeo.com/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = VimeoAPI(request, app.client_id, app.secret,
                          self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(VimeoOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(VimeoOAuthAdapter)
コード例 #9
0
    def get_user_info(self):
        default_params = {'nojsoncallback': '1', 'format': 'json'}
        p = dict({'method': 'flickr.test.login'}, **default_params)
        u = json.loads(self.query(self.api_url + '?' + urlencode(p)))

        p = dict(
            {
                'method': 'flickr.people.getInfo',
                'user_id': u['user']['id']
            }, **default_params)
        user = json.loads(self.query(self.api_url + '?' + urlencode(p)))
        return user


class FlickrOAuthAdapter(OAuthAdapter):
    provider_id = FlickrProvider.id
    request_token_url = 'http://www.flickr.com/services/oauth/request_token'
    access_token_url = 'http://www.flickr.com/services/oauth/access_token'
    authorize_url = 'http://www.flickr.com/services/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = FlickrAPI(request, app.client_id, app.secret,
                           self.request_token_url)
        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(FlickrOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(FlickrOAuthAdapter)