Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. from flask import Flask
  2. from functools import wraps
  3.  
  4. app = Flask(__name__)
  5.  
  6. # Check that the request has the correct `bearer_token`.
  7. def authenticate_admin(func):
  8. @wraps(func)
  9. def wrapped(*args, **kwargs):
  10. bearer_token = vault.get('secret/oauth')['bearer_token']
  11. expected = ("Bearer " + bearer_token)
  12. if expected != request.headers.get('Authorization'):
  13. return jsonify({'error': "Authorization token incorrect"}), 401
  14.  
  15. return func(*args, **kwargs)
  16. return wrapped
  17.  
  18.  
  19. # .... Define a bunch of routes (Elided) ....
  20.  
  21. for rule in app.url_map.iter_rules():
  22. # NEXT LINE IS PSEUDOCODE; IT IS WHAT I WANT TO ACHIEVE
  23. rule.fx = authenticate_admin(rule.fx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement