Working with JWTs in Python

preview_player
Показать описание
In this video, Jose Haro Peralta explains how to work with JWTs in Python.

Chapters:
0:00 What are JSON Web Tokens (JWTs)?
2:29 ID tokens and access tokens
3:14 Types of claims in a JWT
4:22 Signing algorithms for JWTs
4:50 Setting up the environment and installing dependencies
5:42 Producing a JWT with the HS256 algorithm
7:50 Producing a JWT with the RS256 algorithm
9:42 Generating a X.509 signing certificate
10:21 Signing a JWT with a private key
12:38 Validating JWTs with Python
16:05 JWT validation errors
17:18 Wrapping up

JWTs are JSON documents which contain claims. We distinguish two types of JWTs: ID tokens and access tokens.

ID tokens are tokens which carry identifying information about a user, such as their name, username, email, date of birth, and other details. You should NEVER use an ID token to validate access to an API.

Access tokens are tokens which contain claims about the right of a user to access an API or a resource. These are the tokens that we must use to validate access to an API.

The standard claims of an access token are:

• iss (issuer): identifies the authorization server that issued the JWT.
• sub (subject): identifies the subject of the JWT, i.e. the user sending the request to the server.
• aud (audience): indicates the recipient for which the JWT is intended. This is our API server.
• exp (expiration time): when the JWT expires.
• nbf (not before time): time before which the JWT must not be accepted.
• iat (issued at time): when the JWT was issued.
• jti (JWT ID): a unique identifier for the JWT.

JWTs are commonly signed using the HS256 and the RS256 algorithms. HS256 uses a secret to encrypt the token, while RS256 uses a private/public key to sign the token. We use this information to apply the right algorithm to verify the token’s signature.

Some of the articles and websites mentioned in the video are:

In case you're unable to generate the signing certificates with the openssl command as shown in the video, the repo includes an example of private and public keys.

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.

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!
Рекомендации по теме
Комментарии
Автор

Great video - please keep this kind of content coming. As someone trying to learn more advanced concepts in Python this kind of content is very welcome - even if I don't have a project where I need this exact technology right now. Subscribed and liked.

jeffgolden
Автор

Excellent video. You teach more about JWTs in this short video than hours of many courses out there. Congrats!

fmaciel
Автор

Glad this exists. Keep up the good work.

ahmadmtera
Автор

Just discovered your channel! keep the content coming! :)

lfcamacho
Автор

Amazing video. Please keep up the good work:

ihgnmah
Автор

Very nicely explained... Great Content!!! Can you let me know if we use Django framework then in which of it's file should this jwt token be written, i mean in middleware or any custom file that is created??

ankitabhatt
Автор

how to replace pem files in api rest ?

luiscevallos
Автор

from where do we get the value of 'sub' in the payload

shyamt