RUVIDEO
Поделитесь видео 🙏

FastAPI with JWT auth tutorial

In this video, Jose Haro Peralta explains how to add JWT authorization to a FastAPI application.

The code for this tutorial is available in GitHub: https://github.com/abunuwas/fastapi-jwt-tutorial. I'd appreciate if you give it a star! Also feel free to fork out the repo.

0:00 Introduction
0:16 Authorization vs authentication
1:29 Setting up the environment and installing the dependencies
3:06 Project structure
4:49 Implementing token validation in auth.py
8:06 Function for generating JWT tokens
9:32 Adding an authorization middleware to FastAPI
11:04 Excluding public paths from JWT validation
11:48 Excluding preflight (OPTIONS) requests from JWT validation
12:28 Fetching and validating the JWT from the "Authorization" header
15:58 Storing user ID in the request's state object
16:46 Registering the authorization middleware
17:22 Registering CORS middleware
19:12 Starting the uvicorn server
19:32 Fixing CORS configuration
19:54 Testing the auth middleware through the Swagger UI
20:26 Updating the OpenAPI specification with a JWT bearer security scheme
21:54 Overriding FastAPI's default OpenAPI specification
23:25 Generating a JWT token
23:56 Testing the API with an authorized request
24:20 Fixing public key loading in auth.py
25:15 Fixing the audience in the auth module
25:40 Sending a successfully authorized request to the server
26:09 Accessing the user ID in the view functions
28:44 Wrapping up

In this video, we add an authorization layer to the TODO API that we built in the previous tutorial. If you're not familiar with FastAPI and want to understand how the API works, take a look at my "FastAPI tutorial" (https://youtu.be/GRD3z95vs-A).

JWT stands for JSON Web Token and it's the standard way to add authorization to an API. Notice that we say authorization and not authentication: JWT tokens are used to authorize access to an API. JWTs are not used for authentication. Authentication is the process of verifying a user identity, and as part of this process we issue a JWT token.

If you don't know what JWTs are and how they work, take a look at my tutorial "Working with JWTs in Python" (https://youtu.be/VRn8cPc7B_w).

If you liked this video, please like it and share it with your network! You can also subscribe to my channel! All this goes a long way to supporting me to continue creating this kind of content.

I'm also the author of Microservice APIs with Examples in Python. It's a book that explains how to design and build microservices and APIs in Python. /you can get a copy through this link: http://mng.bz/jy4x. Feel free to use the following code to get a 40% discount: slperalta (reach out to me if you have issues using the code).

You can also download two chapters of the book for free from this link: https://www.microapis.io/resources/microservice-apis-in-python

Please let me know in the comments if you liked this video and whether you found it useful.

Let me know also what other kinds of topics you'd like me to address in future videos!

If you have any questions, feel free to reach out ot me in:
- Twitter (https://twitter.com/JoseHaroPeralta)
- LinkedIn (https://www.linkedin.com/in/jose-haro-peralta/)
- Or join my Reddit microapis group (https://www.reddit.com/r/microapis/)

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «FastAPI with JWT auth tutorial», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.