FastAPI backend with users and dependencies
Web applications (or mobile apps, for that matter) are not very useful if they are not secure. You must have heard about tiny errors in the authentication implementations that result in hundreds of thousands or even millions of compromised accounts, potentially exposing sensitive and valuable information.
FastAPI is based on OpenAPI—previously known as Swagger—an open specification for crafting APIs. OpenAPI enables you to define various security schemes, compatible with the various protocols (apiKey
, http
, OAuth 2.0
, openIdConnect
, and so on). While the FastAPI documentation website (https://fastapi.tiangolo.com/tutorial/security/) provides an excellent and detailed tutorial on creating an authentication flow, it is based on the OAuth 2.0
protocol, which uses form data to send the credentials (username and password).
In the following sections, you will devise a simple user model that will enable an authentication flow...