Chapter 7: Securing FastAPI Applications
In the last chapter, we looked at how to connect a FastAPI application to a SQL and NoSQL database. We successfully implemented database methods and updated the existing routes to enable interactions between the application and the database. However, the planner application continues to allow anybody to add an event as opposed to only authenticated users. In this chapter, we will secure the application using JSON Web Token (JWT) and restrict some event operations to only authenticated users.
Securing an application involves the addition of security measures to restrict access to application functionalities from unauthorized entities to prevent hacks or illegal modifications of the application. Authentication is the process of verifying the credentials passed by an entity and authorization simply means giving an entity permission to perform designated actions. When credentials have been verified, the entity is then authorized to carry out...