替代 Django 身份验证

发布于 2024-08-27 22:25:40 字数 143 浏览 8 评论 0原文

需要将 Django 与现有的身份验证系统集成。该系统有自己的数据库、API、登录/注销、编辑个人资料网页和 cookie。

(我可能需要添加一些本地存储/更新的额外配置文件字段)

替代 Django 中开箱即用身份验证的正确方法是什么?

Need to integrate Django with an existing authentication system. That system has it's own database, API, login/logout,edit profile web pages and cookie.

(I may have to add a few additional profile fields stored/updated locally)

What's the proper approach to substitute the out-of-the-box authentication in Django?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

锦欢 2024-09-03 22:25:40

将 django 开箱即用的身份验证替换为您自己的身份验证的正确方法是替换 settings.py 中 AUTHENTICATION_BACKENDS 元组中的类,如 http://docs.djangoproject.com/en/dev/topics/auth/#specifying-authentication -后端。这对于您所描述的问题非常有用。

以这种方式完成身份验证后端的一个很好的示例是 django-cas 。这使用 CAS 在 django 应用程序中进行身份验证。您可以使用它作为模板,只需将挂钩写入您自己的身份验证系统即可。

华泰

The proper approach to substitute authentication from django's out-of-the-box to your own is to substitute your classes in the AUTHENTICATION_BACKENDS tuple in settings.py as described in http://docs.djangoproject.com/en/dev/topics/auth/#specifying-authentication-backends. This is incredibly useful for just the issue you're describing.

A good example of an authentication backend done this way is django-cas. This uses CAS to authenticate in a django application. You can use this as your template and just write hooks into your own authentication system identically.

HTH

樱娆 2024-09-03 22:25:40

当我必须做与您必须做的类似的事情时,我创建了一个自定义身份验证后端。请参阅: http://docs.djangoproject.com /en/dev/topics/auth/#writing-an-authentication-backend

authenticate 函数中,您调用 api 来对用户进行身份验证,然后将它们映射到 某些主键上的 django.contrib.auth.model.User 对象,例如用户名。如果主键不是用户名,我通常会创建一个映射对象,或者将其放入项目的配置文件对象中。

I've created a custom authentication backend when I've had to do something similar to what you have to do. See: http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backend

In the authenticate function you call your api to authenticate the user, and then map them to a django.contrib.auth.model.User object on some primary key, like username for example. If the primary key is something other than username I usually create a mapping object, or put it into the profile object for the project.

如此安好 2024-09-03 22:25:40

这取决于您想如何处理问题。如果您不需要保持现有系统运行,最好的选择是将其数据导入到 django 项目中。

如果身份验证系统必须保持完好,您可能必须为 django.auth 编写一个包装器。我过去使用 SQLAlchemy http://www.sqlalchemy.org 集成到外部来完成此操作数据库。

查看 Django 1.2 多数据库支持 http://djangoadvent 可能会有所帮助。 com/1.2/multiple-database-support

无论哪种情况,我都会尝试将用户信息放入 django.auth 而不是编写自己的身份验证系统。

This depends on how you want to handle the problem. If you don't need to keep the existing system running, your best bet is to import their data into the django project.

If the authentication system must stay in tact, you might have to write a wrapper for django.auth. I've done this in the past using SQLAlchemy http://www.sqlalchemy.org to integrate to the external database.

It might be helpful to take a look at the Django 1.2 multi-db support http://djangoadvent.com/1.2/multiple-database-support

In either case I'd try to get the user information into django.auth rather than to write your own authentication system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文