Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. class MyBasicAuth(BasicAuth):
  2. def check_auth(self,username,password,allowed_roles,resource,method):
  3. return username == 'secretusername' and password == 'secretpass'
  4.  
  5. from flask import request, abort, current_app
  6. from werkzeug.http import parse_authorization_header
  7.  
  8. def check_blueprint_auth():
  9. if 'Authorization' not in request.headers:
  10. print('Authorization header not found for authentication')
  11. return abort(401, 'Authorization header not found for authentication')
  12. header = parse_authorization_header(request.headers['Authorization'])
  13. username = None if header is None else header['username']
  14. password = None if header is None else header['password']
  15.  
  16. return username == 'secretusername' and password == 'secretpass'
  17.  
  18. from flask import Blueprint, current_app as app
  19. # your auth function
  20. from auth import check_blueprint_auth
  21.  
  22. blueprint = Blueprint('prefix_uri', __name__)
  23.  
  24. # this sets the auth function to be called
  25. blueprint.before_request(check_blueprint_auth)
  26.  
  27.  
  28. @blueprint.route('/custom_route/<some_value>', methods=['POST'])
  29. def post_something(some_value):
  30. # something
  31.  
  32. from eve import Eve
  33. # your blueprint
  34. from users import blueprint
  35. from flask import current_app, request
  36.  
  37. app = Eve()
  38. # register the blueprint to the main Eve application
  39. app.register_blueprint(blueprint)
  40.  
  41. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement