Skip to content

Instantly share code, notes, and snippets.

@Torenable
Created February 11, 2018 20:29
Show Gist options
  • Save Torenable/0f92429f4009ad67647d53ff613dd9ce to your computer and use it in GitHub Desktop.
Save Torenable/0f92429f4009ad67647d53ff613dd9ce to your computer and use it in GitHub Desktop.
Auth decorator for Flask
# http://book.pythontips.com/en/latest/decorators.html
from functools import wraps
from flask import request
def requires_auth(func):
@wraps(func)
def wrapper(*args, **kwargs):
auth = request.authorization
if not auto or not check_auth(auth.username, auth.password):
authenticate()
return func(*args, **kwargs)
return wrapper
# @app.route('/api/resources')
# @requires_auth
# def action():
# pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment