为什么我学校的 CAS 服务器在身份验证后没有重定向到我的网站?

发布于 2024-10-24 07:53:19 字数 1347 浏览 3 评论 0原文

我正在尝试制作一个只有滑铁卢大学学生可以使用的网站。它使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人哭 2024-10-31 07:53:19

您确实没有提供足够的信息让别人给您一个有意义的答案。

请尝试以下操作:

  1. 确保按照 django_cas 文档正确设置 CAS_SERVER_URL。
  2. 与您的大学联系,确保允许 CAS 服务器重定向到您的申请。由于有关用户的一些信息在成功身份验证后会传递到应用程序,因此服务器可能配置为仅允许 .uwaterloo.ca 域内托管的站点对用户进行身份验证。

You didn't really provide enough information for someone to give you a meaningful answer.

Try the following:

  1. Make sure that you properly set CAS_SERVER_URL as per the django_cas documentation.
  2. Talk to your university to make sure that the CAS server is allowed to redirect to your application. Since some information about the user is passed to the application upon successful authentication, it's possible that the server is configured to only allow sites hosted inside the .uwaterloo.ca domain to authenticate users.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文