0Pricing
Flask Academy · Lezione

Sessioni e token stateless

Scopra quando JWT è più adatto dei cookie per un'API.

Sessioni e token stateless è una lezione Flask Academy gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Flask Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Flask Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Two Ways to Remember Users

HTTP forgets you between requests. To keep someone logged in, you either store a session on the server or hand the client a signed token.

How Sessions Work

With a session, the server keeps your login state and gives the browser a tiny cookie holding only a session id. Every request, the server looks that id up. 🍪

The Cost of Sessions

Because the server stores the state, it must remember every active user. That server-side state gets heavy and tricky to share across many machines.

How Tokens Flip It

A token carries the user info itself, signed by the server. The server no longer stores anything; it just verifies the signature on each request.

What Stateless Means

Stateless means the server holds no memory of the client. Everything it needs to trust you travels inside the token on each call.

Meet the JWT

A JWT (JSON Web Token) is the standard stateless token. It is a compact, signed string that any server with the key can verify instantly.

Three Parts of a JWT

A JWT has three dot-separated parts: a header, a payload, and a signature. The header names the algorithm used to sign it.

header.payload.signature

Claims Live in the Payload

The middle part holds claims: small facts like the user id or an expiry time. It is encoded, not encrypted, so never put secrets there.

{ "sub": "42", "exp": 1699999999 }

Signature Builds Trust

The signature is made from the header, payload, and a secret only the server knows. Change one byte and verification fails.

When Tokens Win

Tokens shine for APIs and mobile clients that scale across many servers, since no shared session store is needed to verify a caller.

When Sessions Still Fit

For a classic server-rendered website, sessions are simpler and easy to revoke. The right pick depends on your app, not on hype.

Quick Check

Think about what makes a token approach stateless.

Recap

Sessions store state on the server; JWTs push signed state to the client. Tokens stay stateless, making them a great fit for scalable APIs. 🚀

Domande Frequenti

La lezione «Sessioni e token stateless» è gratuita?

Sì — il testo completo di «Sessioni e token stateless» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Flask Academy, passa a CoddyKit PRO. Il corso Flask Academy include 4 lezioni in totale.

Cosa imparerò in «Sessioni e token stateless»?

Scopra quando JWT è più adatto dei cookie per un'API. Eserciti Flask Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Flask Academy?

Non è richiesta alcuna esperienza precedente. Flask Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.

Quanto tempo richiede la lezione «Sessioni e token stateless»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Flask Academy?

Sì. Ogni lezione Flask Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Sessioni e token stateless
  2. Emettere access token al login
  3. Proteggere gli endpoint con jwt_required
  4. Refresh token e scadenza
← Torna a Flask Academy