当前位置: 首页>>代码示例>>Python>>正文


Python backends.get_backends函数代码示例

本文整理汇总了Python中social_auth.backends.get_backends函数的典型用法代码示例。如果您正苦于以下问题:Python get_backends函数的具体用法?Python get_backends怎么用?Python get_backends使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_backends函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_login_providers

def get_login_providers(request, short=False):
    """
    Returns a list of available login providers based on the
    AUTHENTICATION_BACKENDS setting. Each provider is represented as a
    dictionary containing the backend name, name of required parameter if
    required and its verbose name.
    """
    def extract_backend_data(name, klass):
        """
        Helper function which extracts information useful for use in
        templates from SocialAuth subclasses and returns it as a
        dictionary.
        """
        return {
            'name': name,
            'required_field': klass.AUTH_BACKEND.REQUIRED_FIELD_NAME,
            'required_field_verbose': klass.AUTH_BACKEND.REQUIRED_FIELD_VERBOSE_NAME,
        }

    providers = [extract_backend_data(name, auth)
                 for name, auth in get_backends().items()]
    if short:
        return providers[:setting('AUTHENTICATION_PROVIDERS_BRIEF',
                                  DEFAULT_AUTHENTICATION_PROVIDERS_BRIEF)]
    return providers
开发者ID:eruraina,项目名称:ksp_login,代码行数:25,代码来源:context_processors.py

示例2: handle_noargs

 def handle_noargs(self, **options):
     verbosity = int(options.get('verbosity'))
     try:
         from social_auth import version
         from social_auth.backends import get_backends, BaseOAuth
     except ImportError: # pragma: no cover
         raise CommandError("django-social-auth is not installed.")
     request = RequestFactory().get('/')
     for name, backend in get_backends().items():
         if issubclass(backend, BaseOAuth) and backend.enabled():
             if version < (0, 7):
                 # Prior to 0.7 get_key_and_secret was an instance method
                 backend = backend(request, '/')
             # Create providers if they don't already exist
             key, secret = backend.get_key_and_secret()
             defaults = {
                 'request_token_url': getattr(backend, 'REQUEST_TOKEN_URL', '') or '',
                 'authorization_url': getattr(backend, 'AUTHORIZATION_URL', '') or '',
                 'access_token_url': getattr(backend, 'ACCESS_TOKEN_URL', '') or '',
                 'profile_url': '',
                 'consumer_key': key or None,
                 'consumer_secret': secret or None,
             }
             provider, created = Provider.objects.get_or_create(name=name, defaults=defaults)
             if created and verbosity > 0:
                 self.stdout.write('New provider created from "%s" backend.\n' % name)
开发者ID:MaZZly,项目名称:django-all-access,代码行数:26,代码来源:migrate_social_providers.py

示例3: backends_data

def backends_data(user):
    """Return backends data for given user.

    Will return a dict with values:
        associated: UserSocialAuth model instances for currently
                    associated accounts
        not_associated: Not associated (yet) backend names.
        backends: All backend names.

    If user is not authenticated, then first list is empty, and there's no
    difference between the second and third lists.
    """
    available = get_backends().keys()
    values = {'associated': [],
              'not_associated': available,
              'backends': available}

    # user comes from request.user usually, on /admin/ it will be an instance
    # of auth.User and this code will fail if a custom User model was defined
    if isinstance(user, User) and user.is_authenticated():
        associated = user.social_auth.all()
        not_associated = list(set(available) -
                              set(assoc.provider for assoc in associated))
        values['associated'] = associated
        values['not_associated'] = not_associated
    return values
开发者ID:comel,项目名称:django-social-auth,代码行数:26,代码来源:context_processors.py

示例4: refresh_user_data

def refresh_user_data(user):
    
    items = user.social_auth.all()
    key=lambda x: x
    backends = get_backends()
    for item in items:
        try:
            backend = backends[key(item.provider)]
            
            if issubclass(backend, SocialBackend):
                if item.provider != "google":
                    service = SocialServiceLocator.get_instane().build_service_by_name(item.provider)
                    service.pull_user_info(user.id, item.extra_data)
                    
            if issubclass(backend, PhysicalBackend):
                service = PhysicalServiceLocator.get_instane().get_service_by_name(item.provider)
                service.pull_user_info(user.id, item.extra_data)
                
            if issubclass(backend, GenomicsBackend):
                service = GenomicsServiceLocator.get_instane().build_service_by_name(item.provider)
                service.pull_user_info(user.id, item.extra_data)
    
            if issubclass(backend, NutritionBackend):
                service = NutritionServiceLocator.get_instane().build_service_by_name(item.provider)
                service.pull_user_info(user.id, item.extra_data)
                
            if issubclass(backend, HealthBackend):
                service = HealthServiceLocator.get_instane().get_service_by_name(item.provider)
                service.pull_user_info(user.id, item.extra_data)
        except Exception, e:
            print e
开发者ID:wikilife-org,项目名称:datadonor,代码行数:31,代码来源:user_linked_data.py

示例5: context_value

 def context_value():
     keys = [key for key in get_backends().keys()]
     accounts = dict(zip(keys, [None] * len(keys)))
     user = request.user
     if hasattr(user, 'is_authenticated') and user.is_authenticated():
         accounts.update((assoc.provider, assoc)
                 for assoc in UserSocialAuth.get_social_auth_for_user(user))
     return accounts
开发者ID:hzlf,项目名称:openbroadcast.ch,代码行数:8,代码来源:context_processors.py

示例6: admin_home

def admin_home(request):
	potential_providers = backends.get_backends().keys()
	for social in request.user.social_auth.all():
		if social.provider in potential_providers:
			potential_providers = [x for x in potential_providers if x != social.provider]

	return render(request, 'admin_home.html', {
		'potential_providers': potential_providers
	})
开发者ID:tnajdek,项目名称:appengine-playground,代码行数:9,代码来源:views.py

示例7: context_value

 def context_value():
     keys = list(get_backends().keys())
     accounts = dict(list(zip(keys, [None] * len(keys))))
     user = request.user
     if hasattr(user, "is_authenticated") and user.is_authenticated():
         accounts.update(
             (assoc.provider.replace("-", "_"), assoc) for assoc in UserSocialAuth.get_social_auth_for_user(user)
         )
     return accounts
开发者ID:qrees,项目名称:django-social-auth,代码行数:9,代码来源:context_processors.py

示例8: tokens

 def tokens(self):
     """Return access_token stored in extra_data or None"""
     # Make import here to avoid recursive imports :-/
     from social_auth.backends import get_backends
     backend = get_backends().get(self.provider)
     if backend:
         return backend.AUTH_BACKEND.tokens(self)
     else:
         return {}
开发者ID:Quard,项目名称:django-social-auth,代码行数:9,代码来源:models.py

示例9: oauth_discovery

def oauth_discovery(request):

    from social_auth.backends import get_backends

    fiware_auth_backend = get_backends()['fiware']
    endpoints = {
        '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')
开发者ID:caernel,项目名称:wirecloud,代码行数:13,代码来源:views.py

示例10: group_backend_by_type

def group_backend_by_type(items, key=lambda x: x):
    """Group items by backend type."""

    # Beware of cyclical imports!
    from social_auth.backends import \
        get_backends, OpenIdAuth, BaseOAuth, BaseOAuth2, SocialBackend

    result = defaultdict(list)
    backends = get_backends()

    for item in items:
        backend = backends[key(item)]
        if issubclass(backend, SocialBackend):
            result['social'].append(item)
    return dict(result)
开发者ID:wikilife-org,项目名称:datadonor,代码行数:15,代码来源:utils.py

示例11: group_backend_by_type

def group_backend_by_type(items):
    """Group items by backend type."""
    result = defaultdict(list)
    backends_defined = get_backends()

    for item in items:
        name = getattr(item, 'provider', item)
        backend = backends_defined[name]
        if issubclass(backend, OpenIdAuth):
            result['openid'].append(item)
        elif issubclass(backend, BaseOAuth2):
            result['oauth2'].append(item)
        elif issubclass(backend, BaseOAuth1):
            result['oauth'].append(item)
    return dict(result)
开发者ID:AEngh,项目名称:django-social-auth,代码行数:15,代码来源:context_processors.py

示例12: social_auth_by_name_backends

def social_auth_by_name_backends(request):
    """Load Social Auth current user data to context.
    Will add a social_auth object whose attribute names are the names of each
    provider, e.g. social_auth.facebook would be the facebook association or
    None, depending on the logged in user's current associations. Providers
    with a hyphen have the hyphen replaced with an underscore, e.g.
    google-oauth2 becomes google_oauth2 when referenced in templates.
    """
    keys = get_backends().keys()
    accounts = dict(zip(keys, [None] * len(keys)))

    if isinstance(request.user, User) and request.user.is_authenticated():
        for associated in request.user.social_auth.all():
            accounts[associated.provider.replace('-', '_')] = associated

    return {'social_auth': accounts}
开发者ID:comel,项目名称:django-social-auth,代码行数:16,代码来源:context_processors.py

示例13: setUp

    def setUp(self):
        """
        Get the urls we are going to use.
        """
        self.login_url = reverse('auth_login')
        self.reset_password_url = reverse('auth_password_reset')
        self.create_account_url = reverse('registration_register')
        self.change_password_url = reverse('auth_password_change')
        
        self.login_redirect_url = settings.LOGIN_REDIRECT_URL

        self.social_auth_backends = get_backends()
        social_auth_names = self.social_auth_backends.keys()
        
        self.social_auth_login_urls = [reverse('socialauth_begin', kwargs={'backend':backend}) 
                                        for backend in social_auth_names]
开发者ID:georgedorn,项目名称:share2grandma,代码行数:16,代码来源:accounts.py

示例14: refresh_user_physical_data

def refresh_user_physical_data(user):
    
    items = user.social_auth.all()
    key=lambda x: x
    backends = get_backends()
    for item in items:
        try:
            backend = backends[key(item.provider)]
            
                    
            if issubclass(backend, PhysicalBackend):
                service = PhysicalServiceLocator.get_instane().get_service_by_name(item.provider)
                service.pull_user_info(user.id, item.extra_data)
                
        except Exception, e:
            exc_info = sys.exc_info()
            traceback.print_exception(*exc_info)
            del exc_info
开发者ID:wikilife-org,项目名称:datadonor,代码行数:18,代码来源:get_user_physical_data.py

示例15: group_backend_by_type

def group_backend_by_type(items, key=lambda x: x):
    """Group items by backend type."""

    # Beware of cyclical imports!
    from social_auth.backends import \
        get_backends, OpenIdAuth, BaseOAuth, BaseOAuth2

    result = defaultdict(list)

    for item in items:
        backend = get_backends()[key(item)]
        if issubclass(backend, OpenIdAuth):
            result['openid'].append(item)
        elif issubclass(backend, BaseOAuth2):
            result['oauth2'].append(item)
        elif issubclass(backend, BaseOAuth):
            result['oauth'].append(item)
    return dict(result)
开发者ID:sbarysiuk,项目名称:django-social-auth,代码行数:18,代码来源:utils.py


注:本文中的social_auth.backends.get_backends函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。