I'm using the basic code for HTTP Digest authentication on Flask however its not working for me. I always get error code 401. I'm sending the HTTP request with the Postman application.
My code: from flask import Flask from flask_httpauth import HTTPDigestAuth
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret key here'
auth = HTTPDigestAuth()
users = {
"john": "hello",
"Admin": "Admin",
"susan": "bye"
}
@auth.get_password
def get_pw(username):
if username in users:
return users.get(username)
return None
@app.route('/', methods=['GET', 'POST'])
@auth.login_required
def index():
return "Hello, {}!".format(auth.username())
if __name__ == '__main__':
app.run()
The following is the results of the run:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [29/Nov/2020 09:22:32] "POST / HTTP/1.1" 401 -
127.0.0.1 - - [29/Nov/2020 09:22:32] "POST / HTTP/1.1" 401 -