Esempio n. 1
0
    'has_mobile', 'contacts', 'education', 'online', 'counters', 'relation',
    'last_seen', 'activity', 'universities'
]


class VKOAuth2Adapter(OAuth2Adapter):
    provider_id = VKProvider.id
    access_token_url = 'https://oauth.vk.com/access_token'
    authorize_url = 'https://oauth.vk.com/authorize'
    profile_url = 'https://api.vk.com/method/users.get'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs['response']['user_id']
        resp = requests.get(self.profile_url,
                            params={
                                'access_token': token.token,
                                'fields': ','.join(USER_FIELDS),
                                'user_ids': uid
                            })
        resp.raise_for_status()
        extra_data = resp.json()['response'][0]
        email = kwargs['response'].get('email')
        if email:
            extra_data['email'] = email
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(VKOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(VKOAuth2Adapter)
Esempio n. 2
0
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)

from .provider import AmazonProvider


class AmazonOAuth2Adapter(OAuth2Adapter):
    provider_id = AmazonProvider.id
    access_token_url = 'https://api.amazon.com/auth/o2/token'
    authorize_url = 'http://www.amazon.com/ap/oa'
    profile_url = 'https://www.amazon.com/ap/user/profile'
    supports_state = False
    redirect_uri_protocol = 'https'

    def complete_login(self, request, app, token, **kwargs):
        response = requests.get(self.profile_url,
                                params={'access_token': token})
        extra_data = response.json()
        if 'Profile' in extra_data:
            extra_data = {
                'user_id': extra_data['Profile']['CustomerId'],
                'name': extra_data['Profile']['Name'],
                'email': extra_data['Profile']['PrimaryEmail']
            }
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(AmazonOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(AmazonOAuth2Adapter)
Esempio n. 3
0
                                                        OAuth2CallbackView)

from .provider import MailRuProvider


class MailRuOAuth2Adapter(OAuth2Adapter):
    provider_id = MailRuProvider.id
    access_token_url = 'https://connect.mail.ru/oauth/token'
    authorize_url = 'https://connect.mail.ru/oauth/authorize'
    profile_url = 'http://www.appsmail.ru/platform/api'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs['response']['x_mailru_vid']
        data = {
            'method': 'users.getInfo',
            'app_id': app.client_id,
            'secure': '1',
            'uids': uid
        }
        param_list = sorted(list(item + '=' + data[item] for item in data))
        data['sig'] = md5(
            (''.join(param_list) + app.secret).encode('utf-8')).hexdigest()
        response = requests.get(self.profile_url, params=data)
        extra_data = response.json()[0]
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(MailRuOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(MailRuOAuth2Adapter)
Esempio n. 4
0
                                                        OAuth2CallbackView)

from .provider import CoinbaseProvider


class CoinbaseOAuth2Adapter(OAuth2Adapter):
    provider_id = CoinbaseProvider.id

    @property
    def authorize_url(self):
        return 'https://coinbase.com/oauth/authorize'

    @property
    def access_token_url(self):
        return 'https://coinbase.com/oauth/token'

    @property
    def profile_url(self):
        return 'https://coinbase.com/api/v1/users'

    def complete_login(self, request, app, token, **kwargs):
        response = requests.get(self.profile_url,
                                params={'access_token': token})
        extra_data = response.json()['users'][0]['user']
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(CoinbaseOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CoinbaseOAuth2Adapter)
Esempio n. 5
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import DoubanProvider


class DoubanOAuth2Adapter(OAuth2Adapter):
    provider_id = DoubanProvider.id
    access_token_url = 'https://www.douban.com/service/auth2/token'
    authorize_url = 'https://www.douban.com/service/auth2/auth'
    profile_url = 'https://api.douban.com/v2/user/~me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer %s' % token.token}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(DoubanOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DoubanOAuth2Adapter)
Esempio n. 6
0
                                                        OAuth2CallbackView)

from .provider import LinkedInOAuth2Provider


class LinkedInOAuth2Adapter(OAuth2Adapter):
    provider_id = LinkedInOAuth2Provider.id
    access_token_url = 'https://api.linkedin.com/uas/oauth2/accessToken'
    authorize_url = 'https://www.linkedin.com/uas/oauth2/authorization'
    profile_url = 'https://api.linkedin.com/v1/people/~'
    # See:
    # http://developer.linkedin.com/forum/unauthorized-invalid-or-expired-token-immediately-after-receiving-oauth2-token?page=1 # noqa
    access_token_method = 'GET'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = self.get_user_info(token)
        return self.get_provider().sociallogin_from_response(
            request, extra_data)

    def get_user_info(self, token):
        fields = providers.registry \
            .by_id(LinkedInOAuth2Provider.id) \
            .get_profile_fields()
        url = self.profile_url + ':(%s)?format=json' % ','.join(fields)
        resp = requests.get(url, params={'oauth2_access_token': token.token})
        return resp.json()


oauth2_login = OAuth2LoginView.adapter_view(LinkedInOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(LinkedInOAuth2Adapter)
Esempio n. 7
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import AngelListProvider


class AngelListOAuth2Adapter(OAuth2Adapter):
    provider_id = AngelListProvider.id
    access_token_url = 'https://angel.co/api/oauth/token/'
    authorize_url = 'https://angel.co/api/oauth/authorize/'
    profile_url = 'https://api.angel.co/1/me/'
    supports_state = False

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(AngelListOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(AngelListOAuth2Adapter)
Esempio n. 8
0
from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)

from .provider import GoogleProvider


class GoogleOAuth2Adapter(OAuth2Adapter):
    provider_id = GoogleProvider.id
    access_token_url = 'https://accounts.google.com/o/oauth2/token'
    authorize_url = 'https://accounts.google.com/o/oauth2/auth'
    profile_url = 'https://www.googleapis.com/oauth2/v1/userinfo'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={
                                'access_token': token.token,
                                'alt': 'json'
                            })
        resp.raise_for_status()
        extra_data = resp.json()
        login = self.get_provider() \
            .sociallogin_from_response(request,
                                       extra_data)
        return login


oauth2_login = OAuth2LoginView.adapter_view(GoogleOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GoogleOAuth2Adapter)
Esempio n. 9
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
from .provider import OrcidProvider


class OrcidOAuth2Adapter(OAuth2Adapter):
    provider_id = OrcidProvider.id
    # ORCID Public API (not Member API):
    # http://support.orcid.org/knowledgebase/articles/335483-the-public-
    # client-orcid-api
    authorize_url = 'https://orcid.org/oauth/authorize'
    access_token_url = 'https://pub.orcid.org/oauth/token'
    profile_url = 'https://pub.orcid.org/v1.1/%s/orcid-profile'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url % kwargs['response']['orcid'],
                            params={'access_token': token.token},
                            headers={'accept': 'application/orcid+json'})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(OrcidOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OrcidOAuth2Adapter)
Esempio n. 10
0
                                                        OAuth2CallbackView)
from .provider import WindowsLiveProvider


class WindowsLiveOAuth2Adapter(OAuth2Adapter):
    provider_id = WindowsLiveProvider.id
    access_token_url = 'https://login.live.com/oauth20_token.srf'
    authorize_url = 'https://login.live.com/oauth20_authorize.srf'
    profile_url = 'https://apis.live.net/v5.0/me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)

        #example of whats returned (in python format):
        #{'first_name': 'James', 'last_name': 'Smith',
        # 'name': 'James Smith', 'locale': 'en_US', 'gender': None,
        # 'emails': {'personal': None, 'account': '*****@*****.**',
        # 'business': None, 'preferred': '*****@*****.**'},
        # 'link': 'https://profile.live.com/',
        # 'updated_time': '2014-02-07T00:35:27+0000',
        # 'id': '83605e110af6ff98'}

        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(WindowsLiveOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WindowsLiveOAuth2Adapter)
Esempio n. 11
0
from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
import requests

from .provider import DropboxOAuth2Provider


class DropboxOAuth2Adapter(OAuth2Adapter):
    provider_id = DropboxOAuth2Provider.id
    access_token_url = 'https://api.dropbox.com/1/oauth2/token'
    authorize_url = 'https://www.dropbox.com/1/oauth2/authorize'
    profile_url = 'https://api.dropbox.com/1/account/info'
    redirect_uri_protocol = 'https'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = requests.get(self.profile_url,
                                  params={'access_token': token.token})

        # This only here because of weird response from the test suite
        if isinstance(extra_data, list):
            extra_data = extra_data[0]

        return self.get_provider().sociallogin_from_response(
            request, extra_data.json())


oauth_login = OAuth2LoginView.adapter_view(DropboxOAuth2Adapter)
oauth_callback = OAuth2CallbackView.adapter_view(DropboxOAuth2Adapter)
Esempio n. 12
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
from .provider import SoundCloudProvider


class SoundCloudOAuth2Adapter(OAuth2Adapter):
    provider_id = SoundCloudProvider.id
    access_token_url = 'https://api.soundcloud.com/oauth2/token'
    authorize_url = 'https://soundcloud.com/connect'
    profile_url = 'https://api.soundcloud.com/me.json'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'oauth_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(SoundCloudOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(SoundCloudOAuth2Adapter)
Esempio n. 13
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import WeiboProvider


class WeiboOAuth2Adapter(OAuth2Adapter):
    provider_id = WeiboProvider.id
    access_token_url = 'https://api.weibo.com/oauth2/access_token'
    authorize_url = 'https://api.weibo.com/oauth2/authorize'
    profile_url = 'https://api.weibo.com/2/users/show.json'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs.get('response', {}).get('uid')
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token,
                                    'uid': uid})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(WeiboOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WeiboOAuth2Adapter)
Esempio n. 14
0
from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)

from .provider import FoursquareProvider


class FoursquareOAuth2Adapter(OAuth2Adapter):
    provider_id = FoursquareProvider.id
    access_token_url = 'https://foursquare.com/oauth2/access_token'
    # Issue ?? -- this one authenticates over and over again...
    # authorize_url = 'https://foursquare.com/oauth2/authorize'
    authorize_url = 'https://foursquare.com/oauth2/authenticate'
    profile_url = 'https://api.foursquare.com/v2/users/self'

    def complete_login(self, request, app, token, **kwargs):
        # Foursquare needs a version number for their API requests as documented here https://developer.foursquare.com/overview/versioning
        resp = requests.get(self.profile_url,
                            params={
                                'oauth_token': token.token,
                                'v': '20140116'
                            })
        extra_data = resp.json()['response']['user']
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(FoursquareOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FoursquareOAuth2Adapter)
Esempio n. 15
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
from .provider import GitHubProvider


class GitHubOAuth2Adapter(OAuth2Adapter):
    provider_id = GitHubProvider.id
    access_token_url = 'https://github.com/login/oauth/access_token'
    authorize_url = 'https://github.com/login/oauth/authorize'
    profile_url = 'https://api.github.com/user'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(GitHubOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GitHubOAuth2Adapter)
Esempio n. 16
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)

from .provider import BitlyProvider


class BitlyOAuth2Adapter(OAuth2Adapter):
    provider_id = BitlyProvider.id
    access_token_url = 'https://api-ssl.bitly.com/oauth/access_token'
    authorize_url = 'https://bitly.com/oauth/authorize'
    profile_url = 'https://api-ssl.bitly.com/v3/user/info'
    supports_state = False

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()['data']
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(BitlyOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(BitlyOAuth2Adapter)
Esempio n. 17
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import TwitchProvider


class TwitchOAuth2Adapter(OAuth2Adapter):
    provider_id = TwitchProvider.id
    access_token_url = 'https://api.twitch.tv/kraken/oauth2/token'
    authorize_url = 'https://api.twitch.tv/kraken/oauth2/authorize'
    profile_url = 'https://api.twitch.tv/kraken/user'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'oauth_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(TwitchOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(TwitchOAuth2Adapter)
Esempio n. 18
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
from .provider import InstagramProvider


class InstagramOAuth2Adapter(OAuth2Adapter):
    provider_id = InstagramProvider.id
    access_token_url = 'https://instagram.com/oauth/access_token'
    authorize_url = 'https://instagram.com/oauth/authorize'
    profile_url = 'https://api.instagram.com/v1/users/self'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(InstagramOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(InstagramOAuth2Adapter)
Esempio n. 19
0
    access_token_url = 'http://api.odnoklassniki.ru/oauth/token.do'
    authorize_url = 'http://www.odnoklassniki.ru/oauth/authorize'
    profile_url = 'http://api.odnoklassniki.ru/fb.do'
    access_token_method = 'POST'

    def complete_login(self, request, app, token, **kwargs):
        data = {
            'method': 'users.getCurrentUser',
            'access_token': token.token,
            'fields': ','.join(USER_FIELDS),
            'format': 'JSON',
            'application_key': app.key
        }
        suffix = md5('{0:s}{1:s}'.format(
            data['access_token'], app.secret).encode('utf-8')).hexdigest()
        check_list = sorted([
            '{0:s}={1:s}'.format(k, v) for k, v in data.items()
            if k != 'access_token'
        ])
        data['sig'] = md5(
            (''.join(check_list) + suffix).encode('utf-8')).hexdigest()

        response = requests.get(self.profile_url, params=data)
        extra_data = response.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(OdnoklassnikiOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OdnoklassnikiOAuth2Adapter)
Esempio n. 20
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
from .provider import FirefoxAccountsProvider


class FirefoxAccountsOAuth2Adapter(OAuth2Adapter):
    provider_id = FirefoxAccountsProvider.id
    access_token_url = 'https://oauth.accounts.firefox.com/v1/token'
    authorize_url = 'https://oauth.accounts.firefox.com/v1/authorization'
    profile_url = 'https://profile.accounts.firefox.com/v1/profile'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(FirefoxAccountsOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FirefoxAccountsOAuth2Adapter)
Esempio n. 21
0
    return login


class FacebookOAuth2Adapter(OAuth2Adapter):
    provider_id = FacebookProvider.id

    authorize_url = 'https://www.facebook.com/dialog/oauth'
    access_token_url = GRAPH_API_URL + '/oauth/access_token'
    expires_in_key = 'expires'

    def complete_login(self, request, app, access_token, **kwargs):
        return fb_complete_login(request, app, access_token)


oauth2_login = OAuth2LoginView.adapter_view(FacebookOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FacebookOAuth2Adapter)


def login_by_token(request):
    ret = None
    auth_exception = None
    if request.method == 'POST':
        form = FacebookConnectForm(request.POST)
        if form.is_valid():
            try:
                provider = providers.registry.by_id(FacebookProvider.id)
                login_options = provider.get_fb_login_options(request)
                app = providers.registry.by_id(FacebookProvider.id) \
                    .get_app(request)
                access_token = form.cleaned_data['access_token']
                if login_options.get('auth_type') == 'reauthenticate':
Esempio n. 22
0
from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)
from users.socialaccount.providers import registry

from .provider import StackExchangeProvider


class StackExchangeOAuth2Adapter(OAuth2Adapter):
    provider_id = StackExchangeProvider.id
    access_token_url = 'https://stackexchange.com/oauth/access_token'
    authorize_url = 'https://stackexchange.com/oauth'
    profile_url = 'https://api.stackexchange.com/2.1/me'

    def complete_login(self, request, app, token, **kwargs):
        provider = registry.by_id(app.provider)
        site = provider.get_site()
        resp = requests.get(self.profile_url,
                            params={
                                'access_token': token.token,
                                'key': app.key,
                                'site': site
                            })
        extra_data = resp.json()['items'][0]
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(StackExchangeOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(StackExchangeOAuth2Adapter)
Esempio n. 23
0
import requests

from users.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                        OAuth2LoginView,
                                                        OAuth2CallbackView)

from .provider import HubicProvider


class HubicOAuth2Adapter(OAuth2Adapter):
    provider_id = HubicProvider.id
    access_token_url = 'https://api.hubic.com/oauth/token'
    authorize_url = 'https://api.hubic.com/oauth/auth'
    profile_url = 'https://api.hubic.com/1.0/account'
    redirect_uri_protocol = 'https'

    def complete_login(self, request, app, token, **kwargs):
        token_type = kwargs['response']['token_type']
        resp = requests.get(
            self.profile_url,
            headers={'Authorization': '%s %s' % (token_type, token.token)})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(HubicOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(HubicOAuth2Adapter)