示例#1
0
 def test_get_missing_backend(self):
     with self.assertRaisesRegexp(MissingBackend,
                                  'Missing backend "foobar" entry'):
         get_backend(('social.backends.github.GithubOAuth2',
                      'social.backends.facebook.FacebookOAuth2',
                      'social.backends.flickr.FlickrOAuth'),
                     'foobar')
 def test_get_backend(self):
     backend = get_backend((
         'social.backends.github.GithubOAuth2',
         'social.backends.facebook.FacebookOAuth2',
         'social.backends.flickr.FlickrOAuth'
     ), 'github')
     expect(backend).to.equal(GithubOAuth2)
 def test_get_missing_backend(self):
     backend = get_backend((
         'social.backends.github.GithubOAuth2',
         'social.backends.facebook.FacebookOAuth2',
         'social.backends.flickr.FlickrOAuth'
     ), 'foobar')
     expect(backend).to.equal(None)
示例#4
0
 def test_get_backend(self):
     backend = get_backend((
         'social.backends.github.GithubOAuth2',
         'social.backends.facebook.FacebookOAuth2',
         'social.backends.flickr.FlickrOAuth'
     ), 'github')
     self.assertEqual(backend, GithubOAuth2)
示例#5
0
    def get_backend(self, strategy):

        from social.backends.utils import get_backend
        from social.apps.pyramid_app.utils import get_helper

        if self.provider is None or self.provider == '':
            raise ValueError('Provider has not been set')
        backends = get_helper('AUTHENTICATION_BACKENDS')
        return get_backend(backends, self.provider)
示例#6
0
 def get_queryset(self):
     provider = self.request.query_params.get('provider', None)
     user_social_auth = self.request.user.social_auth.filter(provider=provider).first()
     if user_social_auth:  # `.first()` doesn't fail, it just returns None
         backend = get_backend(settings.AUTHENTICATION_BACKENDS, provider)
         friends = backend.get_friends(user_social_auth)
         return friends
     else:
         raise AuthenticationFailed("User is not authenticated with {}".format(provider))
def get_strategy(backends, strategy, storage, request=None, backend=None, *args, **kwargs):
    if backend:
        Backend = get_backend(backends, backend)
        if not Backend:
            raise ValueError("Missing backend entry")
    else:
        Backend = None
    Strategy = module_member(strategy)
    Storage = module_member(storage)
    return Strategy(Backend, Storage, request, backends=backends, *args, **kwargs)
示例#8
0
 def get_queryset(self):
     provider = self.request.query_params.get('provider', None)
     user_social_auth = self.request.user.social_auth.filter(
         provider=provider).first()
     if user_social_auth:  # `.first()` doesn't fail, it just returns None
         backend = get_backend(settings.AUTHENTICATION_BACKENDS, provider)
         friends = backend.get_friends(user_social_auth)
         return friends
     else:
         raise AuthenticationFailed(
             "User is not authenticated with {}".format(provider))
示例#9
0
    def is_valid(self, bundle, request=None):
        if not bundle.data:
            return {'__all__': 'Please add provider and access_token arguments'}

        errors = {}

        provider = bundle.data.get('provider')
        backend = get_backend(settings.AUTHENTICATION_BACKENDS, provider)
        if not backend:
            errors['provider'] = 'This provider is not supported'

        return errors
示例#10
0
def oauth_discovery(request):

    from social.apps.django_app.utils import BACKENDS
    from social.backends.utils import get_backend
    fiware_auth_backend = get_backend(BACKENDS, 'fiware')

    endpoints = {
        'flows': ["Authorization Code Grant", "Resource Owner Password Credentials Grant"],
        'auth_endpoint': fiware_auth_backend.AUTHORIZATION_URL,
        'token_endpoint': fiware_auth_backend.ACCESS_TOKEN_URL,
        'default_redirect_uri': get_absolute_reverse_url('oauth.default_redirect_uri', request),
        'version': '2.0',
    }

    return HttpResponse(json.dumps(endpoints), content_type='application/json; charset=UTF-8')
示例#11
0
def oauth_discovery(request):

    from social.apps.django_app.utils import BACKENDS
    from social.backends.utils import get_backend
    fiware_auth_backend = get_backend(BACKENDS, 'fiware')

    endpoints = {
        'flows': ["Authorization Code Grant", "Resource Owner Password Credentials Grant"],
        'auth_endpoint': fiware_auth_backend.AUTHORIZATION_URL,
        'token_endpoint': fiware_auth_backend.ACCESS_TOKEN_URL,
        'default_redirect_uri': get_absolute_reverse_url('oauth.default_redirect_uri', request),
        'version': '2.0',
    }

    return HttpResponse(json.dumps(endpoints, sort_keys=True), content_type='application/json; charset=UTF-8')
示例#12
0
    def hydrate(self, bundle):
        access_token = bundle.data.get('access_token')
        provider = bundle.data.get('provider')

        social_auth_backend = get_backend(settings.AUTHENTICATION_BACKENDS, provider)

        if social_auth_backend and access_token:
            try:
                social_auth = social_auth_backend(strategy=load_strategy(
                    request=bundle.request,
                    backend=provider,
                ))
                user = social_auth.do_auth(access_token)
                bundle.obj.user = user
            except Exception as e:
                logger.exception(e)
                raise ImmediateHttpResponse(
                    response=http.HttpBadRequest('Invalid access token'))
        return bundle
示例#13
0
def get_strategy(backends,
                 strategy,
                 storage,
                 request=None,
                 backend=None,
                 *args,
                 **kwargs):
    if backend:
        Backend = get_backend(backends, backend)
        if not Backend:
            raise ValueError('Missing backend entry')
    else:
        Backend = None
    Strategy = module_member(strategy)
    Storage = module_member(storage)
    return Strategy(Backend,
                    Storage,
                    request,
                    backends=backends,
                    *args,
                    **kwargs)
示例#14
0
def load_backend(strategy, name, redirect_uri):
    backends = get_helper('AUTHENTICATION_BACKENDS')
    Backend = get_backend(backends, name)
    return Backend(strategy, redirect_uri)
示例#15
0
def load_backend(strategy, name, redirect_uri):
    Backend = get_backend(BACKENDS, name)
    return Backend(strategy, redirect_uri)
示例#16
0
 def test_get_missing_backend(self):
     with self.assertRaisesRegexp(MissingBackend,
                                  'Missing backend "foobar" entry'):
         get_backend(('social.backends.github.GithubOAuth2',
                      'social.backends.facebook.FacebookOAuth2',
                      'social.backends.flickr.FlickrOAuth'), 'foobar')
示例#17
0
 def get_backend(self, strategy):
     return get_backend(strategy.backends, self.provider)
示例#18
0
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import cache_page

from wirecloud.commons.utils.template import TemplateParser
from wirecloud.platform.core.plugins import get_version_hash
from wirecloud.platform.markets.utils import MarketManager
from wirecloud.platform.plugins import WirecloudPlugin, build_url_template

import wirecloud.fiware
from wirecloud.fiware.marketAdaptor.views import get_market_adaptor, get_market_user_data
from wirecloud.fiware.storeclient import UnexpectedResponse

try:
    from social.apps.django_app.utils import BACKENDS
    from social.backends.utils import get_backend
    FIWARE_SOCIAL_AUTH_BACKEND = get_backend(BACKENDS, 'fiware')
    IDM_SUPPORT_ENABLED = 'wirecloud.fiware' in settings.INSTALLED_APPS and 'social.apps.django_app.default' in settings.INSTALLED_APPS
except:
    IDM_SUPPORT_ENABLED = False


def auth_fiware_token(auth_type, token):

    from social.apps.django_app.default.models import UserSocialAuth
    user_data = FIWARE_SOCIAL_AUTH_BACKEND._user_data(token)
    return UserSocialAuth.objects.get(provider='fiware',
                                      uid=user_data['username']).user


class FiWareMarketManager(MarketManager):
示例#19
0
def load_backend(strategy, name, redirect_uri):
    Backend = get_backend(BACKENDS, name)
    return Backend(strategy, redirect_uri)
示例#20
0
def post_social_media(user_social_auth, social_obj):
    backend = get_backend(settings.AUTHENTICATION_BACKENDS,
                          user_social_auth.provider)
    backend.post(user_social_auth, social_obj)
示例#21
0
def load_backend(strategy, name, redirect_uri):
    backends = get_helper('AUTHENTICATION_BACKENDS')
    Backend = get_backend(backends, name)
    return Backend(strategy=strategy, redirect_uri=redirect_uri)
示例#22
0
def load_backend(request_handler, strategy, name, redirect_uri):
    backends = get_helper(request_handler, 'AUTHENTICATION_BACKENDS')
    Backend = get_backend(backends, name)
    return Backend(strategy, redirect_uri)
示例#23
0
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import cache_page

from wirecloud.commons.utils.template import TemplateParser
from wirecloud.platform.core.plugins import get_version_hash
from wirecloud.platform.markets.utils import MarketManager
from wirecloud.platform.plugins import WirecloudPlugin, build_url_template

import wirecloud.fiware
from wirecloud.fiware.marketAdaptor.views import get_market_adaptor, get_market_user_data
from wirecloud.fiware.storeclient import UnexpectedResponse

try:
    from social.apps.django_app.utils import BACKENDS
    from social.backends.utils import get_backend
    FIWARE_SOCIAL_AUTH_BACKEND = get_backend(BACKENDS, 'fiware')
    IDM_SUPPORT_ENABLED = 'wirecloud.fiware' in settings.INSTALLED_APPS and 'social.apps.django_app.default' in settings.INSTALLED_APPS
except:
    IDM_SUPPORT_ENABLED = False


def auth_fiware_token(auth_type, token):

    from social.apps.django_app.default.models import UserSocialAuth
    user_data = FIWARE_SOCIAL_AUTH_BACKEND._user_data(token)
    return UserSocialAuth.objects.get(provider='fiware', uid=user_data['username']).user


class FiWareMarketManager(MarketManager):

    _user = None
示例#24
0
 def get_backend(self, strategy=None):
     strategy = strategy or get_current_strategy()
     if strategy:
         return get_backend(strategy.get_backends(), self.provider)
示例#25
0
 def test_get_backend(self):
     backend = get_backend(('social.backends.github.GithubOAuth2',
                            'social.backends.facebook.FacebookOAuth2',
                            'social.backends.flickr.FlickrOAuth'), 'github')
     self.assertEqual(backend, GithubOAuth2)
示例#26
0
 def load_proper_backend(self):
     backends = load_backends(settings.AUTHENTICATION_BACKENDS)
     backend_class_name = get_backend(backends, self.provider)
     self.strategy.backend = backend_class_name()
示例#27
0
def post_social_media(user_social_auth, social_obj):
    backend = get_backend(settings.AUTHENTICATION_BACKENDS, user_social_auth.provider)
    backend.post(user_social_auth, social_obj)
示例#28
0
 def get_backend(self, strategy):
     return get_backend(strategy.backends, self.provider)
示例#29
0
 def load_proper_backend(self):
     backends = load_backends(settings.AUTHENTICATION_BACKENDS)
     backend_class_name = get_backend(backends, self.provider)
     self.strategy.backend = backend_class_name()