

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Authentication With Passwords
incomplete
2: Password Review
incomplete
3: Types of Authentication
incomplete
4: JWTs
incomplete
5: Authentication With JWTs
incomplete
6: JWT Review
incomplete
7: Revoking JWTs
incomplete
8: Refresh Tokens
incomplete
9: Cookies
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
HTTP cookies are one of the most talked about, but least understood, aspects of the web.
When cookies are talked about in the news, they're usually implied to simply be privacy-stealing bad guys. While cookies can certainly invade your privacy, that's not what they are.
A cookie is a small piece of data that a server sends to a client. The client then dutifully stores the cookie and sends it back to the server on subsequent requests.
Cookies can store any arbitrary data:
The server decides what to put in a cookie, and the client's job is simply to store it and send it back.
Simply put, cookies work through HTTP headers.
Cookies are sent from the server to the client in the Set-Cookie header. Cookies are most popular for web (browser-based) applications because browsers automatically send any cookies they have back to the server in the Cookie header.
Simply put, Chirpy's API is designed to be consumed by mobile apps and other servers. Cookies are primarily for browsers.
A good use-case for cookies is to serve as a more strict and secure transport layer for JWTs within the context of a browser-based application.
For example, when using httpOnly cookies, you can ensure that 3rd party JavaScript that's being executed on your website can't access any cookies. That's a lot better than storing JWTs in the browser's local storage, where it's easily accessible to any JavaScript running on the page.