Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. from functools import wraps
  2. from flask import request, Response
  3. import flask
  4. from flask import Flask
  5. app = Flask(__name__)
  6.  
  7.  
  8. def check_auth(username, password):
  9. """This function is called to check if a username /
  10. password combination is valid.
  11. """
  12. return username == 'admin' and password == 'secret'
  13. @app.route('/')
  14. def authenticate():
  15. """Sends a 401 response that enables basic auth"""
  16. return Response(
  17. 'Could not verify your access level for that URL.\n'
  18. 'You have to login with proper credentials', 401,
  19. {'WWW-Authenticate': 'Basic realm="Login Required"'})
  20.  
  21. def requires_auth(f):
  22. @wraps(f)
  23. def decorated(*args, **kwargs):
  24. auth = request.authorization
  25. if not auth:
  26. return authenticate()
  27. return f(*args, **kwargs)
  28. if auth:
  29. return "yay"
  30. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement