omab / django-social-auth

Django social authentication made simple
https://groups.google.com/group/django-social-auth
BSD 3-Clause "New" or "Revised" License
2.65k stars 756 forks source link

trouble using SOCIAL_AUTH_IMPORT_BACKENDS #106

Closed agrif closed 13 years ago

agrif commented 13 years ago

I'm trying to write a GitHub OAuth2 backend, and I'm writing it inside an app in my root django directory. I've already tested that django-social-auth works fine with the built-in Google OpenID backend, and now I'm working on getting it to recognize my GitHub backend. I've added these to my settings.py:

AUTHENTICATION_BACKENDS = (
    'social_github.backends.github.GitHubBackend',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_IMPORT_BACKENDS = (
    'social_github.backends.github',
)

In this case, my backend is named GitHubBackend, and is in 'social_github/backends/github.py'. Both 'social_github/' and 'social_github/backends/' have a 'init.py' file.

My problem is, when accessing 'http://localhost:8000/login/github/', I get an AttributeError: 'module' object has no attribute '__path__'. Here's the full traceback:

Environment:

Request Method: GET
Request URL: http://localhost:8000/login/github/

Django Version: 1.3 beta 1
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'mptt',
 'reversion',
 'django.contrib.markup',
 'typogrify',
 'podstakannik',
 'social_auth',
 'social_github',
 'django.contrib.admin']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.transaction.TransactionMiddleware')

Traceback:
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_social_auth-0.4.2-py2.6.egg/social_auth/urls.py" in <module>
  4. from social_auth.views import auth, complete, associate, associate_complete, \
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_social_auth-0.4.2-py2.6.egg/social_auth/views.py" in <module>
  11. from social_auth.backends import get_backend
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_social_auth-0.4.2-py2.6.egg/social_auth/backends/__init__.py" in <module>
  734. BACKENDS = get_backends()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django_social_auth-0.4.2-py2.6.egg/social_auth/backends/__init__.py" in get_backends
  720.         for directory, subdir, files in walk(mod.__path__[0]):

Exception Type: AttributeError at /login/github/
Exception Value: 'module' object has no attribute '__path__'

I have no idea what I'm doing wrong, and the documentation for SOCIAL_AUTH_IMPORT_BACKENDS isn't very in-depth. It looks like it's having trouble finding the __path__ attribute on my 'social_github.backends.github' module, but that should be there automatically since it's in a package.

If you could help me figure this out, that would be great. If you need any more information I would be happy to provide it.

omab commented 13 years ago

Extra backends setting must point to the "directory", like INSTALLED_APPS, try with:

SOCIAL_AUTH_IMPORT_BACKENDS = (
    'social_github.backends',
)
agrif commented 13 years ago

Ah! I had tried that, but it looked like it failed. Knowing that it was the right thing to do let me to figure out what was actually wrong: I didn't have a BACKENDS dictionary in github.py.

Thanks for the help!

Once I get this done, I could file a pull request for the GitHub contrib backend if you could use it.