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 ...

Get Building Python Web APIs with FastAPI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.