金字塔中的用户身份验证

发布于 2024-12-10 00:22:43 字数 355 浏览 0 评论 0原文

我正在构建一个网络应用程序,需要在 Django 和 Pyramid 之间进行选择。我决定选择金字塔。

我知道 Pyramid 带有自己的身份验证/授权框架,看起来不错。但我在金字塔中没有看到任何定义用户/组/权限的地方。在 Django 中,这些东西都是免费的。

我正在使用 SQLAlchemy,想知道是否已经构建了可以导入的类似用户/组/权限。我不想自己定义这些对象/映射和密码的散列/加盐。

Django 对这些东西的定义几乎就是我所需要的。

谁能指出我可以使用的东西吗?还是我需要自己动手?

I'm building a webapp and needed to choose between Django and Pyramid. I decided to go with Pyramid.

I understand Pyramid comes with its own authentication/authorization framework which looks nice. But I haven't seen anywhere in Pyramid where users/groups/permissions are defined. In Django these things come for free.

I'm using SQLAlchemy and was wondering if there are similar users/groups/permissions already built that I can import. I'd rather not define these objects/mappings and hash/salting of passwords myself.

Django's definitions of these things are pretty much all I need.

Can anyone point my to something I can use? Or do I need to roll my own?

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

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

发布评论

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

评论(1

没有心的人 2024-12-17 00:22:43

Pyramid 拥有更加灵活的身份验证系统。是的,如果你想要像 Django 的用户/组/权限概念这样简单的东西,那么灵活性可能会让人害怕。

Pyramid 没有“User”对象,因为它不会假设您如何存储数据或使用什么 ORM,因此没有像 contrib.auth 这样适合您的东西。您需要使用 cryptacular 或 passlib 等库自行对密码进行哈希/加盐,这两个库都可以在 PYPI 上找到。

至于想要在 Pyramid 系统中获得用户/组/权限,可以通过定义一个 RootFactory 来实现,该 RootFactory 具有将组映射到权限的 __acl__ 。权限被分配给视图,因此通常是相当静态的。如果您希望团体(金字塔称之为“主体”)充满活力,那也是可以实现的。

我建议查看 Pyramid wiki2 教程,以及枪战演示

如果您计划使用 SQLAlchemy,还有一些第三方软件包可帮助 Pyramid 内的授权。 apex 是一个更完整的堆栈解决方案,并且 ziggurat_foundations 是 SQLAlchemy 之上的较低级别层,可帮助您为应用程序设置用户和组。

您的问题相当高水平,授权是一个“难题”,所以我将在此停止并避免将金字塔教程中已经存在的教程和资源重复到几个第三方示例。如果您有任何具体问题,请随时在另一个问题中提问。

Pyramid has a much more flexible authentication system. And yes, if you want something simple like Django's user/group/permission concept, then flexible might be scary.

Pyramid does not have a "User" object, as it makes no assumptions about how you store your data or what ORM you use, therefore there isn't something for you like contrib.auth. You will need to hash/salt the passwords yourself using a library such as cryptacular or passlib, both found on PYPI.

As far as wanting user/group/permissions within Pyramid's system, this is achievable pretty simply by defining a RootFactory that has an __acl__ that maps groups to permissions. Permissions are assigned to views, thus are pretty static usually. If you'd like the groups (what Pyramid calls "principals") to be dynamic that is also achievable.

I'd suggest looking at the Pyramid wiki2 tutorial, as well as the shootout demo.

There are also a couple third-party packages for assisting with authorization within Pyramid if you plan to be using SQLAlchemy. apex is a more full stack solution, and ziggurat_foundations is a lower-level layer above SQLAlchemy to help you set up users and groups for your application.

Your question is fairly high level and authorization is a "hard problem", so I'll stop here and avoid regurgitating the tutorials and resources that already exist from the Pyramid tutorials to several third-party examples. If you have any specific questions please feel free to ask those in another question.

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