Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def ok_user_and_password(username, password):
  2. return username == app.config['USERNAME'] and password == app.config['PASSWORD']
  3.  
  4. def authenticate():
  5. message = {'message': "Authenticate."}
  6. resp = jsonify(message)
  7.  
  8. resp.status_code = 401
  9. resp.headers['WWW-Authenticate'] = 'Basic realm="Main"'
  10.  
  11. return resp
  12.  
  13. def requires_authorization(f):
  14. @functools.wraps(f)
  15. def decorated(*args, **kwargs):
  16. auth = request.authorization
  17. if not auth or not ok_user_and_password(auth.username, auth.password):
  18. return authenticate()
  19. return f(*args, **kwargs)
  20. return decorated
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement