为什么我学校的 CAS 服务器在身份验证后没有重定向到我的网站?
我正在尝试制作一个只有滑铁卢大学学生可以使用的网站。它使用 CAS 进行身份验证。我开始使用 django_cas 包。几乎完全按照步骤进行。以下是我测试的内容:
重定向到 CAS 登录页面 - 通过
CAS 服务器上的验证用户 - 将
重定向传回网站 - 失败
(更新:添加代码以澄清) 解决方案:
看来我的 CAS_SERVER_URL 错误。 我学校的 CAS 服务器 cas_django 的协议是 https 而不是 http
需要很少的配置:
## in settings.py
CAS_SERVER_URL = 'http://cas-dev.uwaterloo.ca/cas/'
LOGIN_URL = '/accounts/login/'
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django_cas.middleware.CASMiddleware',
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django_cas.backends.CASBackend',
)
## in urls.py
(r'^accounts/login/$', 'django_cas.views.login'),
(r'^accounts/logout/$', 'django_cas.views.logout'),
## in views.py
@login_required
def sample(request):
return render_to_response('sample.html')
我得到的是 404:
请求的 URL /cas/login/http://uwnetwork.shaon.ca/accounts/login/?next=%2Fsample在此服务器上找不到 %2F。
有人知道为什么它无法重定向吗?
I'm trying to make a website that only University of Waterloo students can use. It uses CAS for authentication. I started using the django_cas package. Followed the steps pretty much dead on. Here are the things I tested for:
redirected to CAS login page - pass
verify user on the CAS server - pass
redirect back to website - fail
(UPDATE: adding code to clarify)
SOLUTION:
It seems I had the CAS_SERVER_URL wrong.
The protocol is https instead of http for my school's CAS server
cas_django needs little configuration:
## in settings.py
CAS_SERVER_URL = 'http://cas-dev.uwaterloo.ca/cas/'
LOGIN_URL = '/accounts/login/'
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django_cas.middleware.CASMiddleware',
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django_cas.backends.CASBackend',
)
## in urls.py
(r'^accounts/login/
I got a 404 instead:
The requested URL /cas/login/http://uwnetwork.shaon.ca/accounts/login/?next=%2Fsample%2F was not found on this server.
Anybody know why it would fail to redirect?
, 'django_cas.views.login'),
(r'^accounts/logout/
I got a 404 instead:
The requested URL /cas/login/http://uwnetwork.shaon.ca/accounts/login/?next=%2Fsample%2F was not found on this server.
Anybody know why it would fail to redirect?
, 'django_cas.views.logout'),
## in views.py
@login_required
def sample(request):
return render_to_response('sample.html')
I got a 404 instead:
The requested URL /cas/login/http://uwnetwork.shaon.ca/accounts/login/?next=%2Fsample%2F was not found on this server.
Anybody know why it would fail to redirect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实没有提供足够的信息让别人给您一个有意义的答案。
请尝试以下操作:
You didn't really provide enough information for someone to give you a meaningful answer.
Try the following: