I'm trying flask for the first time and I'm trying to create a rest api with token-based authentication.
Everything's going fine except that I cannot customize the unauthorized response returned by @auth_token_required
which is this default message:
Unauthorized
The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.
I would like it to return a json response which may look something like:
{
"code": 401,
"message": "Unauthorized message"
}
So far I have tried overriding unauthorized_handler
using:
@app.login_manager.unauthorized_handler
def unauthorized():
// code goes here
But it doesn't seem to work for @auth_token_required
decorator.