Closed dmtzs closed 2 years ago
This has to be a bug in your application, so you have to debug it. Add print statements in your verify_function
function to help you determine what's happening in the code.
I already do that but is very curios that doesn prints nothing, its like if that function is not called, also I tried in other computer I have and its the same, Im not able to see the error because everything looks fine but for some reason Im not able to change the credentials, its like that credentials are stored some part in the code for some reason and like I said, im writing prints in the function of the verify_password decorator but Im not able to see nothing, even hardcoded lines of personal messages
It's impossible for me to know. As I said this is something that you need to debug in your application. Why are the prints in verify_password
not printing if the function is called? Are you sure the function is called? If it isn't called, then why is the route not invoking the verify function? The decorator must be missing or incorrectly applied.
Its supposed that the verify_password
method is being called. In this case im testing in an echo endpoint that I create. The routes.py
file is like this way:
from app import models, app, auth
@app.route("/echoAPI", methods=["GET", "POST"])
@auth.login_required
def echoAPI():
respJSON = None
respCode = None
if request.method=="POST" or request.method=="GET":
respCode = 200
respJSON = {
"responseCode": respCode,
"responseMessage": "Success",
"echo": f"{str(dt.now())}",
"method": request.method
}
respJSON= json.dumps(respJSON)
return Response(respJSON, mimetype="application/json"), respCode
@auth.verify_password
def verify_password(username, password):
if username == 'royUser' and password == 'royUser':# Verificar los usuarios y contraseñas permitidas pero desde la base de datos.
return True
else:
return False
And let me know if Im misunderstanding something but I remember that according to the documentation the verify_password
method is called when you try to acces to an endpoint that has the login_required
method so I think that the verify_password
method is called correctly. Of course at the beginning of the file Im importing my auth variable that has the instance of HTTPBasicAuth
from the __init__.py
file. So with this im not able to see the error because im following the documentation for this, Im still not able to print from the verify_password
method something.
@dmtzs It's really not possible for me to tell you what's wrong, but it is definitely something on your side. For example, you claim that your verify function isn't printing anything, yet the code that you show for this function has no prints in it, so I cannot evaluate it since obviously you are showing me something different than what you are trying. You are also not showing complete code, and I cannot tell if you are defining the verify function correctly from a snippet because you are omitting a lot of details.
Closing this issue because it's already fixed.
Hello Miguel,
I have a init.py file in which for authorization i have define the next code lines:
and the variable
auth
in being imported to myroutes.py
file, also im in tests now so thats why i hardcoded the username and password in the code, that part of the file is like this way:The problem here is that every time I change the hardcoded credentials im not able to authenticate me, because it doesnt matter that I change the hardcoded credentials the only way to authenticate me is using the first hardcoded credentials even if I already change that credentials. Could you give some light in this topic or Im doing something wrong? Of course I read already the documentation and follow your examples and im not able to change the hardcoded credentials.
Thank you in advance for the help