I am developing a Flask
0.12 app with Blueprints and I am trying to use Flask-JWT
(0.3.2) for authentication.
None of the tutorials that I can see for Flask-JWT use Blueprints.
There is a usually a block of code in each example, that does something like this:
app = Flask(__name__)
jwt = JWT(app, authenticate, identity)
In a blueprinted flask app the structure tends to be more like this:
__init__.py:
from swarm.controllers.main import main
from swarm.controllers.grid import grid
from swarm.controllers.address import address
def create_app(object_name):
app = Flask(__name__)
...
app.register_blueprint(main)
app.register_blueprint(grid)
app.register_blueprint(address)
controllers/main.py:
main = Blueprint('main', __name__)
controllers/grid.py:
grid = Blueprint('grid', __name__)
controllers/address.py:
address = Blueprint('address', __name__)
How would I reference Flask-JWT
and use its decorators in the controllers?
It might prove easier to answer this question by showing how to add JWT decorators to a standard example such as blueprintexample in the flask source code o Michał Karzyński's REST API demo.