It accompanied the tutorial Token-Based Authentication With Flask, which has since been retired from Real Python. The code targets a 2017 dependency stack (including PyJWT 1.4.2) and is kept here for reference only. Please don't use it as the starting point for a new project or as a model for production authentication code.
For current Flask material, see the Flask by Example learning path.
- Fork/Clone
- Activate a virtualenv
- Install the requirements
Update project/server/config.py, and then run:
$ export APP_SETTINGS="project.server.config.DevelopmentConfig"or
$ export APP_SETTINGS="project.server.config.ProductionConfig"Set a SECRET_KEY:
$ export SECRET_KEY="change_me"Create the databases in psql:
$ psql
# create database flask_jwt_auth
# create database flask_jwt_auth_test
# \qCreate the tables and run the migrations:
$ python manage.py create_db
$ python manage.py db init
$ python manage.py db migrate$ python manage.py runserverAccess the application at the address http://localhost:5000/
Want to specify a different port?
$ python manage.py runserver -h 0.0.0.0 -p 8080
Without coverage:
$ python manage.py testWith coverage:
$ python manage.py cov