July 2018
Intermediate to advanced
324 pages
8h 14m
English
Authentication is an essential feature to secure the REST API from unauthorized access. So, in order to implement the authentication layer, we are going to use the JWT mechanism. Here, we are going to design two REST APIs for registering a user and for login access.
To persist the data related to users, we would need to define a user model. The following is the code snippet of the User model.
File—auth/models.py:
import refrom datetime import datetimefrom app.config.models import BaseModelfrom sqlalchemy.orm import synonymfrom werkzeug.security import generate_password_hash, check_password_hashfrom app import dbclass User(BaseModel, db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) ...