Jose Haro Peralta Profile picture
Mar 27 โ€ข 7 tweets โ€ข 2 min read
๐Ÿ’ก๐–๐ก๐š๐ญ ๐š๐ซ๐ž ๐‰๐–๐“๐ฌ?๐Ÿ’ก

If you work with APIs, you've probably come across JWTs. JWT stands for ๐‰๐’๐Ž๐ ๐–๐ž๐› ๐“๐จ๐ค๐ž๐ง, and it's a JSON document that contains information about a user. We call the properties of a JWT claims.

๐Ÿงต๐Ÿงต๐Ÿงต๐Ÿงต
1/

#API #jwt #auth #WebSecurity
There're two types of JWTs:

๐Ÿ‘‰ ๐ˆ๐ƒ ๐ญ๐จ๐ค๐ž๐ง๐ฌ are tokens carrying user-identifying data like their name and email. You should ๐๐„๐•๐„๐‘ use an ID token to validate access to an API.

๐Ÿ‘‰ ๐€๐œ๐œ๐ž๐ฌ๐ฌ ๐ญ๐จ๐ค๐ž๐ง๐ฌ are tokens with claims about the right to access an API.

2/
We use access tokens to validate access to an API.

A JWT has three components: header, payload, and signature

๐Ÿ‘‡

๐Ÿ”ธ ๐‡๐ž๐š๐๐ž๐ซ: it identifies the document as a JWT and contains metadata, such as the algorithm and the key ID used to sign the token.

3/
๐Ÿ”ธ ๐๐š๐ฒ๐ฅ๐จ๐š๐: the set of claims that a) identify a user in ID tokens or b) claim the user's access to the API (access tokens).

๐Ÿ”ธ ๐’๐ข๐ ๐ง๐š๐ญ๐ฎ๐ซ๐ž: a signature produced by combining the header and the payload. The signature verifies that the JWT is legit.

4/
๐‰๐–๐“ ๐œ๐ฅ๐š๐ข๐ฆ๐ฌ

The standard claims of an access token are:

- ๐ข๐ฌ๐ฌ (issuer): identifies the authorization server that issued the JWT.
- ๐ฌ๐ฎ๐› (subject): identifies the subject of the JWT, i.e. the user sending the request to the server.

5/
- ๐š๐ฎ๐ (audience): the JWT's recipient (aka the API server).
- ๐ž๐ฑ๐ฉ (expiration time): when the JWT expires.
- ๐ง๐›๐Ÿ (not before time): time before which the JWT mustn't be accepted.
- ๐ข๐š๐ญ (issued at time): when the JWT was issued.
- ๐ฃ๐ญ๐ข (JWT ID): a JWT unique ID.

6/
๐‰๐–๐“ ๐ฌ๐ข๐ ๐ง๐ข๐ง๐  ๐š๐ฅ๐ ๐จ๐ซ๐ข๐ญ๐ก๐ฆ๐ฌ

JWTs are signed using the HS256 and the RS256 algorithms:

๐Ÿ”ถ ๐‡๐’๐Ÿ๐Ÿ“๐Ÿ” uses a secret to encrypt the token.

๐Ÿ”ถ ๐‘๐’๐Ÿ๐Ÿ“๐Ÿ” uses a private/public key.

We use this info to apply the right algorithm to verify the tokenโ€™s signature.

7/

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Jose Haro Peralta

Jose Haro Peralta Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(