flutterdartauthenticationflaskdigest-authentication

DigestAuth using dart getting 401


I have been trying to figure out Digest authentication in dart. Whatever I do the server is returning 401 Unauthorized.

Following is the code I used to login.

I am using http_auth library.

final url = Uri.parse("http://127.0.0.1:5000/ping");
client = DigestAuthClient("admin", "password");
final response = await client.get(url);
print(response.statusCode);

I am trying to login into a flask server written in python which uses flask-httpauth library, below is the code of the server

-> save the below code as app.py
pip install Flask-HTTPAuth flask
flask run --host 0.0.0.0 --port 5000
from flask import Flask
from flask_httpauth import HTTPDigestAuth

app = Flask(__name__)
app.config["SECRET_KEY"] = "some-random-key"
auth = HTTPDigestAuth()

@auth.get_password
def get_pw(username):
    print(username)
    return {'admin': 'password'}.get(username)

@app.route('/ping', methods=['GET'])
@auth.login_required
def ping():
    return {'success': True}

Any pointers in the right direction would be helpful here.


Solution

  • The reason was because I haven't put a trailing slash at the end of the URL

    http://127.0.0.1:5000/ping/ <- this