Django 自定义身份验证后端需要密码吗?

发布于 2024-07-15 10:20:42 字数 281 浏览 5 评论 0原文

我的大学处理身份验证的方式如下:我们将用户重定向到网站,他们输入用户名和密码,然后使用查询字符串中传递的用户名和登录密钥重定向回我们。 当我们返回用户时,我们调用大学数据库中的存储过程,该过程获取用户名、登录密钥和 IP 地址,并告诉我们这是否有效。

我设置了一个 Django 自定义身份验证后端来处理这一切。 我是否让它能够接受密码参数(因为我们实际上并没有获取他们的密码),这会有什么不同吗? 现在,我已将其设置为将登录密钥作为密码参数。 对我来说,将其更改为登录密钥而不是密码,是好是坏,还是两者都不是?

Here's how my university handles authentication: we redirect the user to a website, they enter in their username and password, then they get redirected back to us with the username and a login key passed in the query string. When we get the user back, we call a stored procedure in the university's database that takes the username, login key, and ip address and tells us if this is valid.

I've got a Django custom authentication backend set up to handle our end of all of this. Does it make any difference one way or another whether I make it able to accept a password argument (since we're not actually taking their password)? Right now, I have it set up so that it takes the login key as the password argument. Would it be good, bad, or neither for me to change this to take this as say, login_key instead of as password?

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

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

发布评论

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

评论(1

遇见了你 2024-07-22 10:20:42

Django 文档这样说:

无论哪种方式,身份验证都应该检查
它获得的凭据,并且应该
返回匹配的 User 对象
这些凭证,如果凭证
是有效的。 如果它们无效,则
应该返回 None。

“任一方式”是指authenticate() 方法是否采用用户名/密码组合,或者仅采用令牌。 您的场景介于这两者之间,因此我认为“最佳”答案是编写您的authenticate() 来获取用户名和登录密钥,并根据需要返回正确的用户或无。

The Django docs say this:

Either way, authenticate should check
the credentials it gets, and it should
return a User object that matches
those credentials, if the credentials
are valid. If they're not valid, it
should return None.

The 'Either way' refers to whether the authenticate() method takes a username/password combination, or just a token. Your scenario falls between those two, so I'd think that the 'best' answer would be to write your authenticate() to take a username and a login key, and return the right User or None as appropriate.

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