Python flask_httpauth.HTTPTokenAuth() Examples
The following are 1
code examples of flask_httpauth.HTTPTokenAuth().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_httpauth
, or try the search function
.
Example #1
Source File: server.py From captcha22 with MIT License | 5 votes |
def __init__(self, source): self.auth = HTTPBasicAuth() self.source = source @self.auth.verify_password def verify_password(username, password): for user in self.source.users: if user.username == username: return check_password_hash(user.password, password) return False @self.auth.error_handler def unauthorized(): # return 403 instead of 401 to prevent browsers from displaying the default # auth dialog return make_response(jsonify({'message': 'Unauthorized access'}), 403) self.second_auth = HTTPTokenAuth() @self.second_auth.verify_token def verify_token(token): self.clean_tokens() headers = request.headers token = headers.get("X-Api-Key") for user in self.source.users: for current_token in user.tokens: if user.tokens[current_token][0] == token: return True return False @self.second_auth.error_handler def unauthorized(): # return 403 instead of 401 to prevent browsers from displaying the default # auth dialog return make_response(jsonify({'message': 'Unauthorized access'}), 403)