def test_auth_object(): builder = EnvironBuilder( auth=Authorization("digest", {"username": "******", "password": "******"}) ) request = builder.get_request() assert request.headers["Authorization"].startswith("Digest ")
def get_auth(self): if 'X-API-Key' in request.headers: return Authorization('api_key', {'token': request.headers['X-API-Key']}) return None
if auth_type == 'basic': try: username, password = auth_info.decode('base64').split(':', 1) except Exception, e: return return Authorization('basic', { 'username': username, 'password': password }) elif auth_type == 'digest': auth_map = parse_dict_header(auth_info) for key in 'username', 'realm', 'nonce', 'uri', 'nc', 'cnonce', \ 'response': if not key in auth_map: return return Authorization('digest', auth_map) def parse_www_authenticate_header(value, on_update=None): """Parse an HTTP WWW-Authenticate header into a :class:`~werkzeug.datastructures.WWWAuthenticate` object. :param value: a WWW-Authenticate header to parse. :param on_update: an optional callable that is called every time a value on the :class:`~werkzeug.datastructures.WWWAuthenticate` object is changed. :return: a :class:`~werkzeug.datastructures.WWWAuthenticate` object. """ if not value: return WWWAuthenticate(on_update=on_update) try:
# coding: utf-8 from flask.ext.httpauth import HTTPBasicAuth from functools import wraps from flask import request, make_response, current_app from json import loads, dumps from werkzeug.datastructures import Authorization anonymous = Authorization('basic', {'username': '******', 'password': None}) def user_exists(username): return current_app.database.get_user(username=username) def user_not_found(): error_msg = { "status": 1, "value": "User not found in service", "message": "Please register in service" } res = make_response(dumps(error_msg)) res.status_code = 401 return res def authentificate_failed(): error_msg = { "status": 1, "value": "Authentification was failed", "message": "Please try again"