From: Matías Aguirre Date: Sun, 14 Aug 2011 07:16:03 +0000 (-0300) Subject: Add setting to control enabled backends. Closes gh-112 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=6cc7d20466a4c1bc535a75a7a4328317ded5d199;p=django-social-auth.git Add setting to control enabled backends. Closes gh-112 --- diff --git a/README.rst b/README.rst index 4317ccd..739a846 100644 --- a/README.rst +++ b/README.rst @@ -128,6 +128,12 @@ Configuration Take into account that backends **must** be defined in AUTHENTICATION_BACKENDS_ or Django won't pick them when trying to authenticate the user. +- Define desired backends for your site:: + + SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'google-oauth', 'facebook', ...) + + All backends are enabled by default. + - Setup needed OAuth keys (see OAuth_ section for details):: TWITTER_CONSUMER_KEY = '' diff --git a/doc/configuration.rst b/doc/configuration.rst index 08dc90b..fc0405d 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -37,6 +37,12 @@ Configuration Take into account that backends **must** be defined in AUTHENTICATION_BACKENDS_ or Django won't pick them when trying to authenticate the user. +- Define desired backends for your site:: + + SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'google-oauth', 'facebook', ...) + + All backends are enabled by default. + - Setup needed OAuth keys (see OAuth_ section for details):: TWITTER_CONSUMER_KEY = '' diff --git a/example/settings.py b/example/settings.py index 158e790..c55fdfb 100644 --- a/example/settings.py +++ b/example/settings.py @@ -74,6 +74,8 @@ AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', ) +#SOCIAL_AUTH_ENABLED_BACKENDS = ('google', 'google-oauth', 'facebook') + LOGIN_REDIRECT_URL = '/' try: diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index e1bb572..ea546fa 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -710,6 +710,7 @@ SOCIAL_AUTH_IMPORT_SOURCES = ( def get_backends(): backends = {} + enabled_backends = _setting('SOCIAL_AUTH_ENABLED_BACKENDS') for mod_name in SOCIAL_AUTH_IMPORT_SOURCES: try: @@ -725,7 +726,9 @@ def get_backends(): # register only enabled backends backends.update(((key, val) for key, val in sub.BACKENDS.items() - if val.enabled())) + if val.enabled() and + (not enabled_backends or + key in enabled_backends))) except (ImportError, AttributeError): pass return backends