简体   繁体   中英

Django Openstack Authentication

I'm new to Django, so this may just be showing a massive hole in my knowledge. I'm trying to us django-openstack-auth to authenticate my webapp to Openstack, as the two will be very closely linked. However I can't figure out how to get the custom authentication backend to work. I've tried following the instructions at http://django-openstack-auth.readthedocs.org/en/latest/index.html however they're a little sparse, and there isn't actually a working example.

Below are the config files I've changed, however its not functioning properly, some extensive googling has resulted in me deciding I'm the first person to ever use this module (?) (actually or I'm just the most stupid)

settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'openstack_auth',
)

#AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend','openstack_auth.backend.KeystoneBackend',)
AUTHENTICATION_BACKENDS = ('openstack_auth.backend.KeystoneBackend',)
OPENSTACK_KEYSTONE_URL = "http://192.168.XX.XX:35357/v2.0"

urls.py:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('openstack_auth.urls')),
)

I even got despirate and tried authenticating manually in a view, but this just produces authentication errors too...

from django.http import HttpResponse
from django.contrib.auth import authenticate, login

def home(request):
    user = authenticate(username='user', password='password')
    if user is None:
        login(request, user)
    else:
        return HttpResponse("Hello")

Any pointers would be massively appreciated...

Many thanks

Alex

I was puzzled for a very long time too for this, too. I think it is caused by a bug inside django-openstack-auth.

(I was using django-openstack-auth 1.1.7) If you look into authenticate(...) function in /Lib/site-packages/openstack_auth/backend.py, you'll see auth_url is not being read from settings. This will cause an exception several lines down when you try to run keystone_client.Client(...).

When I updated to django-openstack-auth-1.1.9, this was added into the function:

if auth_url is None:
    auth_url = settings.OPENSTACK_KEYSTONE_URL

I have this question too. It seems http://django-openstack-auth.readthedocs.org/en/latest/index.html works with Django1.1 and you can't use it with higher versions of Django like 3.0.3. So, we need to write our app instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM