url = 'https://twitter.com/account/verify_credentials.json'

    def get_user_info(self):
        user = simplejson.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 get_user_info(self, request, app):
        client = TwitterAPI(request, app.key, app.secret,
                            self.request_token_url)
        user_info = client.get_user_info()
        uid = user_info['id']
        extra_data = { 'profile_image_url': user_info['profile_image_url'], 
                       'screen_name': user_info['screen_name'] }
        data = dict(twitter_user_info=user_info,
                    username=user_info['screen_name'])
        return uid, data, extra_data


oauth_login = OAuthLoginView.adapter_view(TwitterOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(TwitterOAuthAdapter)
oauth_complete = OAuthCompleteView.adapter_view(TwitterOAuthAdapter)
Exemple #2
0
class HatenaAPI(OAuth):
    """
    Verifying hatena credentials
    """
    url = 'http://n.hatena.com/applications/my.json'

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


class HatenaOAuthAdapter(OAuthAdapter):
    provider_id = HatenaProvider.id
    request_token_url = 'https://www.hatena.com/oauth/initiate'
    access_token_url = 'https://www.hatena.com/oauth/token'
    authorize_url = 'https://www.hatena.ne.jp/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = HatenaAPI(request, app.client_id, app.secret,
                           self.request_token_url)
        # access_token for example:
        # {'oauth_token': 'hoge', 'oauth_token_secret': 'fuga', 'url_name': 'h3poteto', 'display_name': '平仮名3文字ぽてと'}

        extra_data = client.get_user_info()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth_login = OAuthLoginView.adapter_view(HatenaOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(HatenaOAuthAdapter)
Exemple #3
0
    def get_user_info(self):
        user = simplejson.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):
        client = TwitterAPI(request, app.key, app.secret,
                            self.request_token_url)
        extra_data = client.get_user_info()
        uid = extra_data['id']
        user = User(username=extra_data['screen_name'], first_name=extra_data['name'])
        account = SocialAccount(user=user,
                                uid=uid,
                                provider=TwitterProvider.id,
                                extra_data=extra_data)
        return SocialLogin(account)


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

Exemple #4
0
    OAuthLoginView,
)

from .provider import TrelloProvider


class TrelloOAuthAdapter(OAuthAdapter):
    provider_id = TrelloProvider.id
    request_token_url = 'https://trello.com/1/OAuthGetRequestToken'
    authorize_url = 'https://trello.com/1/OAuthAuthorizeToken'
    access_token_url = 'https://trello.com/1/OAuthGetAccessToken'

    def complete_login(self, request, app, token, response):
        # we need to get the member id and the other information
        info_url = '{base}?{query}'.format(
            base='https://api.trello.com/1/members/me',
            query=urlencode({
                'key': app.key,
                'token': response.get('oauth_token')
            }))
        resp = requests.get(info_url)
        resp.raise_for_status()
        extra_data = resp.json()
        result = self.get_provider().sociallogin_from_response(
            request, extra_data)
        return result


oauth_login = OAuthLoginView.adapter_view(TrelloOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(TrelloOAuthAdapter)
Exemple #5
0
    authorize_url = 'https://trello.com/1/OAuthAuthorizeToken'
    profile_url = 'https://trello.com/1/members/me'

    def complete_login(self, request, app, token):
        consumer = oauth.Consumer(key=app.key, secret=app.secret)
        access_token = oauth.Token(key=token.token, secret=token.token_secret)
        client = oauth.Client(consumer, access_token)
        client.ca_certs = certifi.where()

        response, data = client.request(self.profile_url)

        extra_data = json.loads(data)

        full_name = extra_data.get('fullName', '').split(' ')
        user = User(
            username=extra_data.get('username', ''),
            email=extra_data.get('email', ''),
            first_name=full_name[0] if full_name else '',
            last_name=full_name[1] if len(full_name) > 1 else '',
        )
        account = SocialAccount(
            user=user,
            uid=extra_data.get('id'),
            extra_data=extra_data,
            provider=self.provider_id
        )
        return SocialLogin(account)

oauth_login = OAuthLoginView.adapter_view(TrelloOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(TrelloOAuthAdapter)
Exemple #6
0
    elif app_settings.PROVIDERS['kony'].get('environment', 'prod') == 'prod':
        url = 'https://api.kony.com/api/v1_0/whoami'

    def get_user_info(self):
        raw_json = self.query(self.url, method="POST")
        user_info = json.loads(raw_json)
        return user_info


class KonyOAuthAdapter(OAuthAdapter):
    provider_id = KonyProvider.id

    if app_settings.PROVIDERS['kony'].get('environment', 'dev') == 'dev':
        request_token_url = 'https://manage.dev-kony.com/oauth/request_token'
        access_token_url = 'https://manage.dev-kony.com/oauth/access_token'
        authorize_url = 'https://manage.dev-kony.com/oauth/authorize'
    elif app_settings.PROVIDERS['kony'].get('environment', 'dev') == 'prod':
        request_token_url = 'https://manage.kony.com/oauth/request_token'
        access_token_url = 'https://manage.kony.com/oauth/access_token'
        authorize_url = 'https://manage.kony.com/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = KonyAPI(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(KonyOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(KonyOAuthAdapter)
Exemple #7
0
    OAuthLoginView,
)

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)
Exemple #8
0
from .provider import DropboxProvider


class DropboxAPI(OAuth):
    """
    Verifying dropbox 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)
Exemple #9
0
        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)
Exemple #10
0
from allauth.socialaccount.providers.oauth.views import (
    OAuthAdapter,
    OAuthCallbackView,
    OAuthLoginView,
)
from datetime import datetime

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)
Exemple #11
0
    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)
Exemple #12
0
        #extra_data = resp.json()
        #if app_settings.QUERY_EMAIL and not extra_data.get('email'):
        #    extra_data['email'] = self.get_email(token)
        client = GoodreadsAPI(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
        )

    def get_email(self, token):
        email = None
        params = {'access_token': token.token}
        resp = requests.get(self.emails_url, params=params)
        emails = resp.json()
        if resp.status_code == 200 and emails:
            email = emails[0]
            primary_emails = [
                e for e in emails
                if not isinstance(e, dict) or e.get('primary')
            ]
            if primary_emails:
                email = primary_emails[0]
            if isinstance(email, dict):
                email = email.get('email', '')
        return email


oauth2_login = OAuthLoginView.adapter_view(GoodreadsOAuthAdapter)
oauth2_callback = OAuthCallbackView.adapter_view(GoodreadsOAuthAdapter)
Exemple #13
0
    authorize_url = 'https://websignon.warwick.ac.uk/oauth/authenticate'

    def complete_login(self, request, app, token):
        client = WarwickAPI(request, app.client_id, app.secret,
                            self.request_token_url)
        extra_data = client.get_user_info()
        uid = extra_data['user']
        user = User(username=extra_data['user'],
                    email=extra_data.get('email', ''),
                    first_name=extra_data.get('firstname', ''),
                    last_name=extra_data.get('lastname', ''))
                    
        email_addresses = []
        if user.email:
            email_addresses.append(EmailAddress(email=user.email,
                                                verified=True,
                                                primary=True))
                                                
        account = SocialAccount(user=user,
                                uid=uid,
                                provider=WarwickProvider.id,
                                extra_data=extra_data)
        return SocialLogin(account, email_addresses=email_addresses)

OAuthLoginView._get_client = _get_client
OAuthCallbackView._get_client = _get_client

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

                                                         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)
Exemple #15
0
    OAuthLoginView,
)

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)
Exemple #16
0
    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):
        client = VimeoAPI(request, app.client_id, app.secret,
                          self.request_token_url)
        extra_data = client.get_user_info()
        uid = extra_data['id']
        user = get_adapter() \
            .populate_new_user(name=extra_data.get('display_name'),
                               username=extra_data.get('username'))
        account = SocialAccount(user=user,
                                provider=self.provider_id,
                                extra_data=extra_data,
                                uid=uid)
        return SocialLogin(account)


oauth_login = OAuthLoginView.adapter_view(VimeoOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(VimeoOAuthAdapter)
Exemple #17
0
from allauth.socialaccount.providers.oauth.views import (OAuthAdapter,
                                                         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)
Exemple #18
0
    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)
Exemple #19
0
    elif app_settings.PROVIDERS['kony'].get('environment', 'prod') == 'prod':
        url = 'https://api.kony.com/api/v1_0/whoami'

    def get_user_info(self):
        raw_json = self.query(self.url, method="POST")
        user_info = json.loads(raw_json)
        return user_info


class KonyOAuthAdapter(OAuthAdapter):
    provider_id = KonyProvider.id

    if app_settings.PROVIDERS['kony'].get('environment', 'dev') == 'dev':
        request_token_url = 'https://manage.dev-kony.com/oauth/request_token'
        access_token_url = 'https://manage.dev-kony.com/oauth/access_token'
        authorize_url = 'https://manage.dev-kony.com/oauth/authorize'
    elif app_settings.PROVIDERS['kony'].get('environment', 'dev') == 'prod':
        request_token_url = 'https://manage.kony.com/oauth/request_token'
        access_token_url = 'https://manage.kony.com/oauth/access_token'
        authorize_url = 'https://manage.kony.com/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = KonyAPI(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(KonyOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(KonyOAuthAdapter)
Exemple #20
0
                    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):
        client = LinkedInAPI(request, app.client_id, app.secret,
                             self.request_token_url)
        extra_data = client.get_user_info()
        uid = extra_data['id']
        user = get_adapter() \
            .populate_new_user(email=extra_data.get('email-address'),
                               first_name=extra_data.get('first-name'),
                               last_name=extra_data.get('last-name'))
        account = SocialAccount(user=user,
                                provider=self.provider_id,
                                extra_data=extra_data,
                                uid=uid)
        return SocialLogin(account)


oauth_login = OAuthLoginView.adapter_view(LinkedInOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(LinkedInOAuthAdapter)
Exemple #21
0
API_BASE = "https://api.500px.com/v1"


class FiveHundredPxAPI(OAuth):
    """
    Verifying 500px credentials
    """

    url = API_BASE + "/users"

    def get_user_info(self):
        return json.loads(self.query(self.url))["user"]


class FiveHundredPxOAuthAdapter(OAuthAdapter):
    provider_id = FiveHundredPxProvider.id
    request_token_url = API_BASE + "/oauth/request_token"
    access_token_url = API_BASE + "/oauth/access_token"
    authorize_url = API_BASE + "/oauth/authorize"

    def complete_login(self, request, app, token, response):
        client = FiveHundredPxAPI(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(FiveHundredPxOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(FiveHundredPxOAuthAdapter)
Exemple #22
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):
        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)
Exemple #23
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):
        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)
Exemple #24
0
                        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):
        client = LinkedInAPI(request, app.client_id, app.secret,
                             self.request_token_url)
        extra_data = client.get_user_info()
        uid = extra_data['id']
        user = get_adapter() \
            .populate_new_user(email=extra_data.get('email-address'),
                               first_name=extra_data.get('first-name'),
                               last_name=extra_data.get('last-name'))
        account = SocialAccount(user=user,
                                provider=self.provider_id,
                                extra_data=extra_data,
                                uid=uid)
        return SocialLogin(account)

oauth_login = OAuthLoginView.adapter_view(LinkedInOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(LinkedInOAuthAdapter)
    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)
Exemple #26
0
from .provider import DropboxProvider


class DropboxAPI(OAuth):
    """
    Verifying dropbox 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)
Exemple #27
0
API_BASE = 'https://api.500px.com/v1'


class FiveHundredPxAPI(OAuth):
    """
    Verifying 500px credentials
    """
    url = API_BASE + '/users'

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


class FiveHundredPxOAuthAdapter(OAuthAdapter):
    provider_id = FiveHundredPxProvider.id
    request_token_url = API_BASE + '/oauth/request_token'
    access_token_url = API_BASE + '/oauth/access_token'
    authorize_url = API_BASE + '/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = FiveHundredPxAPI(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(FiveHundredPxOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(FiveHundredPxOAuthAdapter)
Exemple #28
0
    def get_user_info(self):
        raw_xml = self.query(self.url)
        try:
            user_element = ElementTree.fromstring(raw_xml).find('user')
            user_info = user_element.attrib
            user_avatar = user_element.find('img')
            if user_avatar is not None:
                user_info.update({'avatar': user_avatar.attrib.get('href')})
            return user_info
        except (ExpatError, KeyError, IndexError):
            return None


class OpenStreetMapOAuthAdapter(OAuthAdapter):
    provider_id = OpenStreetMapProvider.id
    request_token_url = 'https://www.openstreetmap.org/oauth/request_token'
    access_token_url = 'https://www.openstreetmap.org/oauth/access_token'
    authorize_url = 'https://www.openstreetmap.org/oauth/authorize'

    def complete_login(self, request, app, token, response):
        client = OpenStreetMapAPI(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(OpenStreetMapOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(OpenStreetMapOAuthAdapter)
Exemple #29
0
        try:
            avatar = dom.getElementsByTagName('img')[0].getAttribute('href')
        except IndexError:
            avatar = None
        return {
            'id': user.getAttribute('id'),
            'username': user.getAttribute('display_name'),
            'account_created': user.getAttribute('account_created'),
            'avatar': avatar
        }


class OSMOAuthAdapter(OAuthAdapter):
    provider_id = OSMProvider.id
    request_token_url = 'https://www.openstreetmap.org/oauth/request_token'
    access_token_url = 'https://www.openstreetmap.org/oauth/access_token'
    authorize_url = 'https://www.openstreetmap.org/oauth/authorize'

    def complete_login(self, request, app, token, response, **kwargs):
        client = OSMAPI(request, app.client_id, app.secret,
                        self.request_token_url)
        extra_data = client.get_user_info()
        result = self.get_provider().sociallogin_from_response(
            request, extra_data)

        return result


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