1

我是 Django 的新手,所以这可能只是在我的知识中显示出一个巨大的漏洞。我正在尝试使用 django-openstack-auth 向 Openstack 验证我的 webapp,因为两者将非常紧密地联系在一起。但是我不知道如何让自定义身份验证后端工作。我已经尝试按照http://django-openstack-auth.readthedocs.org/en/latest/index.html上的说明进行操作,但是它们有点稀疏,实际上并没有一个有效的示例。

下面是我更改的配置文件,但是它不能正常运行,一些广泛的谷歌搜索导致我决定我是第一个使用这个模块的人(?)(实际上或者我只是最愚蠢的)

设置.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"

网址.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')),
)

我什至感到绝望并尝试在视图中手动进行身份验证,但这也只会产生身份验证错误......

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")

任何指针将不胜感激......

非常感谢

亚历克斯

4

2 回答 2

0

我也为此困惑了很久。我认为这是由 django-openstack-auth 内部的错误引起的。

(我使用的是 django-openstack-auth 1.1.7)如果您查看 /Lib/site-packages/openstack_auth/backend.py 中的 authenticate(...) 函数,您会看到 auth_url 没有从设置中读取。当您尝试运行 keystone_client.Client(...) 时,这将导致几行异常。

当我更新到 django-openstack-auth-1.1.9 时,它被添加到函数中:

if auth_url is None:
    auth_url = settings.OPENSTACK_KEYSTONE_URL
于 2015-01-30T08:18:10.677 回答
0

我也有这个问题。似乎http://django-openstack-auth.readthedocs.org/en/latest/index.html可与 Django1.1 一起使用,您不能将其与 3.0.3 等更高版本的 Django 一起使用。所以,我们需要编写我们的应用程序。

于 2020-02-27T14:18:30.573 回答