Struttura e firma dell’ID Token
Scomponga l’header, il payload e la firma dell’ID Token (JWT), comprendendo come viene firmato e quali informazioni contiene.
Struttura e firma dell’ID Token è una lezione OAuth2 & OpenID Connect Deep Dive 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 OAuth2 & OpenID Connect Deep Dive, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso OAuth2 & OpenID Connect Deep Dive include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Meet the ID Token
In OpenID Connect (OIDC), the ID Token is a crucial piece of information. It's a security token that contains claims about the authentication of an end-user by an Authorization Server.
Think of it as a digital ID card for the user, issued after they successfully log in.
ID Tokens Are JWTs
ID Tokens are always formatted as JSON Web Tokens (JWTs). A JWT is a compact, URL-safe means of representing claims to be transferred between two parties.
Every JWT has three main parts, separated by dots:
- Header
- Payload
- Signature
The Header: What Algorithm?
The first part of an ID Token is the Header. It's a JSON object that describes the token itself, like what type of token it is and the algorithm used to sign it.
alg: The cryptographic algorithm used for signing (e.g., RS256, HS256).typ: The type of token, which is usually"JWT".
Header in Action
When you decode the base64url-encoded header, you'll see a JSON object like this. This tells you how the token was secured.
{
"alg": "RS256",
"typ": "JWT",
"kid": "someKeyId"
}The kid (Key ID) helps find the correct public key for verification.
Decoding Header Example
The header is base64url encoded. Here's how you might decode a JWT header string in Java. This helps reveal its content.
import java.util.Base64;
import java.nio.charset.StandardCharsets;
public class JwtDecoder {
public static void main(String[] args) {
String encodedHeader = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InNvbWVLZXlJZCJ9";
byte[] decodedBytes = Base64.getUrlDecoder().decode(encodedHeader);
String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
System.out.println("Decoded Header:");
System.out.println(decodedString);
}
}The Payload: Claims About You
The second part is the Payload. This is where the actual "claims" about the user and the authentication event are stored. Claims are statements about an entity (typically the user).
Standard claims you'll often see include:
iss: Issuer (who issued the token).sub: Subject (unique identifier for the user).aud: Audience (who the token is for).exp: Expiration Time (when the token expires).iat: Issued At Time (when the token was issued).
Payload in Action
Similar to the header, the payload is also a base64url-encoded JSON object. It contains the identity information you need.
{
"iss": "https://example.com/auth",
"sub": "user123",
"aud": "myAppClientId",
"exp": 1678886400,
"iat": 1678882800,
"name": "Alice Wonderland"
}exp and iat are Unix timestamps.
The Signature: Ensuring Trust
The third and final part is the Signature. This is critical for security! It's used to verify that the token hasn't been tampered with and that it comes from a legitimate issuer.
The signature is created by taking the encoded header, the encoded payload, and a secret key or private key, and running them through the cryptographic algorithm specified in the header.
Verifying the Signature
When your application receives an ID Token, it uses the public key (provided by the Issuer) to verify the signature. It re-computes the signature using the header, payload, and the public key.
If the re-computed signature matches the token's signature, you can trust that:
- The token hasn't been altered.
- It was issued by the expected Authorization Server.
Quick Check on JWT
You've learned that ID Tokens are structured as JWTs, with three distinct parts. Each part plays a vital role in conveying and securing user identity information.
Recap: ID Token Anatomy
Great job! You now understand the fundamental structure of an ID Token.
- Header: Describes the token and signing algorithm.
- Payload: Contains identity claims about the user.
- Signature: Ensures the token's integrity and authenticity.
Each part is base64url encoded and separated by dots, forming a secure and verifiable digital identity for the user.
Domande Frequenti
La lezione «Struttura e firma dell’ID Token» è gratuita?
Sì — il testo completo di «Struttura e firma dell’ID Token» è 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 OAuth2 & OpenID Connect Deep Dive, passa a CoddyKit PRO. Il corso OAuth2 & OpenID Connect Deep Dive include 4 lezioni in totale.
Cosa imparerò in «Struttura e firma dell’ID Token»?
Scomponga l’header, il payload e la firma dell’ID Token (JWT), comprendendo come viene firmato e quali informazioni contiene. Eserciti OAuth2 & OpenID Connect Deep Dive 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 OAuth2 & OpenID Connect Deep Dive?
Non è richiesta alcuna esperienza precedente. OAuth2 & OpenID Connect Deep Dive 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 «Struttura e firma dell’ID Token»?
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 OAuth2 & OpenID Connect Deep Dive?
Sì. Ogni lezione OAuth2 & OpenID Connect Deep Dive 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
- Struttura e firma dell’ID Token
- JWS e set JWK
- Revoca e introspezione dei token
- Convalidare i claim standard degli ID token