Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. const req_url = 'http://localhost:5000/'
  2. let resp = fetch(req_url, {
  3. method: 'POST',
  4. mode: 'no-cors',
  5. headers: new Headers({
  6. 'Authorization' : 'Basic dXNlcjpwd2Q=', // user:pwd
  7. }),
  8.  
  9. }).then((resp) => resp)
  10.  
  11. #!/usr/bin/env python3
  12. from functools import wraps
  13. from flask import Flask, request, Response
  14.  
  15. app = Flask(__name__)
  16.  
  17. def check_auth(username, password):
  18. return username == 'user' and password == 'pwd'
  19.  
  20. def authenticate():
  21. return Response(
  22. 'Could not verify your access level for that URL.n'
  23. 'You have to login with proper credentials', 401,
  24. {'WWW-Authenticate': 'Basic realm="Login Required"'})
  25.  
  26. def requires_auth(f):
  27. @wraps(f)
  28. def decorated(*args, **kwargs):
  29. auth = request.authorization
  30. if not auth or not check_auth(auth.username, auth.password):
  31. return authenticate()
  32. return f(*args, **kwargs)
  33. return decorated
  34.  
  35. @app.route('/', methods=['POST', 'GET'])
  36. @requires_auth
  37. def secret_page():
  38. return """
  39. <!doctype HTML>
  40. <html>
  41. <head></head>
  42. <body><h1>Success!</h1></body>
  43. </html>
  44. """
  45.  
  46.  
  47. if __name__ == '__main__':
  48. app.run(debug=True)
  49.  
  50. const req_url = 'http://localhost:5000/'
  51. let resp = fetch(req_url, {
  52. method: 'POST',
  53. mode: 'no-cors',
  54. headers: {
  55. 'Authorization' : 'Basic dXNlcjpwd2Q=',
  56. },
  57.  
  58. }).then((resp) => resp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement