Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from functools import wraps
- app = Flask(__name__)
- # Check that the request has the correct `bearer_token`.
- def authenticate_admin(func):
- @wraps(func)
- def wrapped(*args, **kwargs):
- bearer_token = vault.get('secret/oauth')['bearer_token']
- expected = ("Bearer " + bearer_token)
- if expected != request.headers.get('Authorization'):
- return jsonify({'error': "Authorization token incorrect"}), 401
- return func(*args, **kwargs)
- return wrapped
- # .... Define a bunch of routes (Elided) ....
- for rule in app.url_map.iter_rules():
- # NEXT LINE IS PSEUDOCODE; IT IS WHAT I WANT TO ACHIEVE
- rule.fx = authenticate_admin(rule.fx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement