Flask HTTP Basicauth - 它是如何工作的? [英] Flask HTTP Basicauth - How does it work?
问题描述
我正在尝试使用 Flask 和 HTTP 基本身份验证创建登录系统.我的问题是,从数据库提供用户信息是我的责任,还是 basicauth 为我创建和访问这些数据库?如果没有,我可以用什么来做到这一点?
I'm trying to create a login system using Flask and HTTP Basic Auth. My question is, is it my responsibility to provide user information from databases, or does basicauth create and access those databases for me? If it doesn't, what can I use to do that?
推荐答案
Werkzeug 可以为您解码 Basic Authorization 标头,将其解码为用户名和密码.剩下的就看你想用这些信息做什么了.
Werkzeug can decode the Basic Authorization header for you, into the username and password. The rest is up to you to see what you want to do with that information.
request.authorization
属性 返回一个 Authorization
对象.对于基本的认证头,只设置了username
和password
.
Flask-Login
之类的项目可以提供帮助您可以使用基本授权管理更复杂的登录,并将其与您提供的用户模型联系起来.该模型可以存储在数据库中或您想要的任何其他内容中.
A project like Flask-Login
can help you manage more complex logins with Basic Authorization, and tie that in with a user model you provide. That model can be stored in a database or anything else you so desire.
您可以查看 Flask-Security 以获得使用 Flask 的更完全集成的安全包-提供基本身份验证和基于会话的登录的登录和其他包.
And you can look at Flask-Security for a more fully integrated security package that uses Flask-Login and other packages to provide Basic Authentication and session based logins.
这篇关于Flask HTTP Basicauth - 它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!