Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyBasicAuth(BasicAuth):
- def check_auth(self,username,password,allowed_roles,resource,method):
- return username == 'secretusername' and password == 'secretpass'
- from flask import request, abort, current_app
- from werkzeug.http import parse_authorization_header
- def check_blueprint_auth():
- if 'Authorization' not in request.headers:
- print('Authorization header not found for authentication')
- return abort(401, 'Authorization header not found for authentication')
- header = parse_authorization_header(request.headers['Authorization'])
- username = None if header is None else header['username']
- password = None if header is None else header['password']
- return username == 'secretusername' and password == 'secretpass'
- from flask import Blueprint, current_app as app
- # your auth function
- from auth import check_blueprint_auth
- blueprint = Blueprint('prefix_uri', __name__)
- # this sets the auth function to be called
- blueprint.before_request(check_blueprint_auth)
- @blueprint.route('/custom_route/<some_value>', methods=['POST'])
- def post_something(some_value):
- # something
- from eve import Eve
- # your blueprint
- from users import blueprint
- from flask import current_app, request
- app = Eve()
- # register the blueprint to the main Eve application
- app.register_blueprint(blueprint)
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement