HTTP Digest Authentication on flask not working for me

Viewed 438

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 -
1 Answers

What is not working? I copied the code and it ran for me on Win 10 and Chrome.

127.0.0.1 - - [17/Aug/2021 13:40:28] "GET / HTTP/1.1" 401 -
127.0.0.1 - - [17/Aug/2021 13:40:32] "GET / HTTP/1.1" 200 -

Flask==2.0.1

Flask-HTTPAuth==4.4.0

Maybe it is how you are formating the call. Check debug for more information or run a proxy between you and the service to capture the detailsl.

Related