def requires_basic_auth(resource):
@functools.wraps(resource)<EOL>def decorated(*args, **kwargs):<EOL><INDENT>'''<STR_LIT>'''<EOL>auth = flask.request.authorization<EOL>user = check_credentials(auth.username, auth.password)<EOL>if not auth or user is None:<EOL><INDENT>log.warn('<STR_LIT>', credentials=auth)<EOL>return auth_failed()<EOL><DEDENT>log.info('<STR_LIT>', credentials=auth)<EOL>flask.g.user = user<EOL>return resource(*args, **kwargs)<EOL><DEDENT>return decorated<EOL>
Flask decorator protecting ressources using username/password scheme