What Is an ID Token in Keycloak? — The signed business card that says who just logged in
A complete, beginner-friendly breakdown of what an ID token actually is, what's inside it, how Keycloak issues it, and why it's not the same thing as an access token.
Imagine you attend a large conference. At check-in, the organizers verify your identity and hand you a laminated badge with your name, photo, company, and a tamper-proof holographic seal printed right on it. Anyone glancing at the badge instantly knows who you are — no phone call back to the front desk required, because the seal proves it hasn’t been forged. An ID token in Keycloak is exactly this badge, translated into the world of software: a small, signed, self-contained piece of data that proves who just logged in, which the receiving application can trust on sight.
1What Is an ID Token?
Let’s start with a precise, plain-English definition.
An ID token is a piece of digital proof, issued by Keycloak right after a successful login, that tells an application exactly who the user is. It’s built as a JSON Web Token (JWT) — a compact, signed block of text containing structured information called claims, such as the user’s unique ID, name, and email address. Because it’s digitally signed by Keycloak, any application receiving it can verify the information hasn’t been tampered with, without needing to ask Keycloak “is this really true?” every single time.
Think of a passport. When you cross a border, the officer doesn’t call your home country to verify your identity from scratch — they trust the passport itself, because it carries an official government seal that’s extremely hard to forge. An ID token works the same way: it carries Keycloak’s digital “seal” (a cryptographic signature), so the receiving application can trust the claims inside it immediately, without a live round-trip check.
JWT (JSON Web Token)
A compact, URL-safe text format for representing signed pieces of information.
Claim
One individual fact inside a token — like “name,” “email,” or “issued at time.”
Issuer
Who created and signed the token — in this case, the specific Keycloak realm.
Signature
A cryptographic seal proving the token’s contents haven’t been altered since it was issued.
The ID token belongs to a well-established, widely adopted industry standard called OpenID Connect, which sits on top of the older OAuth 2.0 standard. This matters because it means ID tokens aren’t a Keycloak-specific invention — any application built to understand OpenID Connect can work with an ID token issued by Keycloak, or by a completely different identity provider, without special custom logic.
2Why the ID Token Exists — The Problem It Solves
To appreciate the ID token, it helps to see the gap it was specifically designed to fill.
Before OpenID Connect became widespread, the underlying OAuth 2.0 standard was excellent at handing out tokens that granted access to resources — but it was never actually designed to answer the specific question, “who is this person?” Applications improvised ways to squeeze identity information out of access tokens, which led to inconsistent, insecure, and hard-to-verify approaches across different systems.
Access tokens were meant to say “this bearer can call this API,” not “this specific person is logged in.” Using them as a stand-in for identity information was fragile and inconsistent across different systems and vendors.
OpenID Connect — and with it, the ID token — was created specifically to close this gap: a standardized, purpose-built token whose entire job is representing “who logged in,” cleanly separated from tokens whose job is “what can be accessed.”
Imagine a keycard that both opens doors and was somehow also expected to double as your employee ID photo badge. It would work, awkwardly, but it conflates two very different jobs. The ID token exists so that “proving who you are” and “proving what you’re allowed to access” can be handled by two clean, separate, purpose-built pieces of proof.
3Core Concepts: Claims, Structure, and Signing
Let’s open up the token itself and see what’s actually inside.
An ID token is made of three parts, joined together by dots, though as a beginner you mainly need to understand what the middle part — the payload — contains: a set of claims.
sub (Subject)
A unique, stable identifier for the specific user who logged in.
iss (Issuer)
Identifies which Keycloak realm issued this token.
aud (Audience)
States which application this token was intended for — a safeguard against misuse elsewhere.
exp (Expiration)
The exact time after which this token should no longer be trusted.
iat (Issued At)
The timestamp recording exactly when the token was created.
name / email
Optional profile information about the user, included if the application requested it.
If the ID token were a printed badge, “sub” would be your unique badge number, “iss” would be the conference organizer’s logo printed on it, “aud” would be a note saying “valid at the Main Hall entrance only,” “exp” would be the printed expiration date, and “name”/”email” would simply be your printed name and contact details.
Why Signing Matters
Keycloak signs every ID token cryptographically using a private key that only it holds. Any application can verify this signature using Keycloak’s matching public key, confirming the token genuinely came from Keycloak and that none of its claims were altered afterward — all without needing to contact Keycloak directly for every single check.
4Architecture — Where the ID Token Fits Inside Keycloak
A look at the components involved in creating and verifying an ID token.
Token Endpoint
The Keycloak endpoint that issues the ID token (alongside other tokens) once a login succeeds.
Signing Key
The private cryptographic key Keycloak uses to sign every token it issues, unique to each realm.
JWKS Endpoint
A publicly reachable endpoint publishing the public keys applications need to verify a token’s signature.
Client Scopes
Configuration determining which optional claims (like email or custom attributes) get included in the ID token for a given application.
Every realm in Keycloak has its own signing keys and its own issuer identity, meaning ID tokens from one realm are never mistakenly trusted as valid for another. This isolation is a deliberate security boundary, not an accident of design.
5How the ID Token Is Issued, Step by Step
Tracing exactly when and how an ID token comes into existence during a login.
User Completes the Login Flow
The user successfully passes through whatever authentication steps the flow requires.
Application Exchanges a Code for Tokens
Following the OpenID Connect standard, the application swaps a short-lived authorization code for the actual tokens.
Keycloak Builds the Claims
Keycloak assembles the relevant claims — subject, issuer, audience, expiration, and any requested profile data.
Keycloak Signs the Token
The assembled claims are cryptographically signed using the realm’s private signing key.
Token Is Returned to the Application
Alongside the access token and, if requested, a refresh token, the signed ID token is handed back.
Application Verifies the Signature
Using Keycloak’s published public key, the application confirms the token is genuine and unaltered.
Application Reads the Claims
Once verified, the application trusts the claims inside to know exactly who is now logged in.
sequenceDiagram
participant U as User
participant App as Application
participant KC as Keycloak
U->>App: Complete login
App->>KC: Exchange authorization code
KC->>KC: Build claims and sign token
KC-->>App: Return ID token + access token
App->>App: Verify signature using public key
App->>App: Read claims (sub, name, email)
App-->>U: Show logged-in user profile
6Data Flow and Lifecycle — From Issuance to Expiration
An ID token has a defined lifespan, and understanding it prevents a common source of bugs.
flowchart LR
A[Token Issued at Login] --> B[Application Reads Claims Once]
B --> C[Token Stored Briefly by Application]
C --> D{Still Within Expiration?}
D -->|Yes| E[Claims Still Considered Valid Snapshot]
D -->|No| F[Token Considered Stale/Expired]
F --> G[New Login or Token Refresh Needed]
An ID token is meant to be a snapshot of “who logged in, at that moment” — it’s typically read once, right after login, to establish the user’s identity in the application, rather than being repeatedly re-checked on every subsequent action the way an access token might be.
7ID Token vs Access Token vs Refresh Token
This is the single most important distinction to get right when working with Keycloak tokens.
| Token | Purpose | Who It’s Meant For |
|---|---|---|
| ID Token | Proves who the user is (identity) | The application itself, to know who’s logged in |
| Access Token | Grants permission to call APIs on the user’s behalf | The API or resource server being called |
| Refresh Token | Used to obtain new tokens once the current ones expire | The application, kept securely, never sent to APIs |
At that same conference, your laminated name badge (ID token) tells anyone who you are. A separate wristband (access token) is what actually lets you into the VIP lounge — bouncers check the wristband, not the badge. And a claim ticket kept safely in your bag (refresh token) is what you’d show at the help desk later to get a fresh wristband once the old one expires, without going through registration all over again.
A frequent beginner error is sending the ID token to an API to authorize a request, the way an access token is meant to be used. APIs should check the access token, not the ID token — the ID token is meant for the application’s own use, to know who’s logged in.
8Advantages, Disadvantages, and Trade-offs
Understanding both sides helps you use ID tokens appropriately rather than by habit.
Advantages
- Self-contained — an application can read identity claims without an extra network call
- Cryptographically signed, so tampering can be detected instantly
- Standardized through OpenID Connect, so it works across many tools and platforms
- Cleanly separates “who you are” from “what you can access”
- Short-lived by design, limiting how long a stolen token stays useful
Disadvantages / Trade-offs
- Once issued, its claims are a fixed snapshot — it won’t reflect later profile changes automatically
- If misused as an access token for APIs, it creates a real security weakness
- Its content is only base64-encoded, not encrypted, so it shouldn’t hold sensitive secrets
- Verifying signatures correctly requires careful, correct implementation on the receiving end
“Signed” is not the same as “encrypted.” Anyone who intercepts an ID token can read its claims in plain text — they just can’t alter them without breaking the signature. This is exactly why sensitive secrets should never be placed inside an ID token’s claims.
9Security Considerations for ID Tokens
A handful of checks separate a safely handled ID token from a security liability.
Verify the Signature
Always confirm the token was genuinely signed by the expected Keycloak realm before trusting anything inside it.
Check the Audience
Confirm the “aud” claim matches this specific application, preventing a token meant for one app from being reused in another.
Check Expiration
Reject any token whose “exp” timestamp has already passed, even if the signature is otherwise valid.
Check the Issuer
Confirm the “iss” claim matches the exact, expected Keycloak realm, not just any realm on any server.
Checking a passport at a border isn’t just glancing at the photo — officers also confirm it hasn’t expired, that it was issued by a recognized country, and that the security seal hasn’t been tampered with. Skipping any single one of these checks defeats the entire purpose of having a passport in the first place.
Problem
Trusting the claims inside an ID token without actually verifying its signature first.
Why It’s Harmful
Without signature verification, nothing stops an attacker from crafting a fake token with false claims — like pretending to be a different user entirely — and the application would have no way to detect the forgery.
Correct Approach
Always verify the token’s signature, issuer, audience, and expiration before trusting any claim inside it, using a well-established library rather than custom-written verification code.
10Monitoring, Logging, and Metrics
Keeping an eye on token issuance and validation reveals a lot about system health and potential abuse.
Token Issuance Volume
Tracking how many ID tokens are issued over time helps spot unusual spikes in login activity.
Signature Validation Failures
Repeated failures may indicate outdated cached public keys, misconfiguration, or an attempted forgery.
Expired Token Usage Attempts
Applications rejecting expired tokens frequently may point to a client that isn’t refreshing sessions correctly.
Audience Mismatch Errors
A token meant for one application appearing at another can indicate a misconfiguration or a genuine security concern.
Every token issuance is recorded as part of Keycloak’s login event logging, giving administrators a clear trail of exactly when, for whom, and to which application each identity token was granted.
11Design Patterns and Anti-Patterns
Well-tested habits keep ID token usage clean and secure.
Pattern: Use the ID Token Only to Establish Identity
Read it once, right after login, to know who the user is in the application’s own session — then rely on the access token for any subsequent API calls.
Pattern: Cache Public Keys Sensibly
Fetch and cache Keycloak’s public signing keys for a reasonable period rather than fetching them fresh on every single verification, while still refreshing them periodically to handle key rotation.
Pattern: Request Only the Claims You Need
Configure client scopes to include only the profile information the application actually uses, keeping the token smaller and more privacy-conscious.
Problem
Sending the ID token as the authorization credential when calling a backend API.
Why It’s Harmful
ID tokens are meant for the application itself, not for API authorization, and were never designed with API access-control semantics (like scopes) in mind — using them this way blurs a boundary that exists specifically for security clarity.
Correct Approach
Send the access token to APIs, and keep the ID token strictly for the application’s own identity handling.
12Best Practices and Common Mistakes
A practical checklist for working with ID tokens correctly.
Always Validate Before Trusting
Never skip signature, issuer, audience, or expiration checks, even in a trusted internal environment.
Use a Trusted Library
Rely on well-maintained OpenID Connect libraries for verification rather than writing custom parsing logic.
Never Store Secrets in Claims
Remember that ID token contents are readable by anyone who intercepts them — treat them as visible, not confidential.
Refresh Identity Data Periodically
Since claims are a snapshot from login time, re-authenticate or request fresh tokens if the application needs up-to-date profile information later.
Frequent mistakes include treating the ID token as an access token for APIs, skipping signature verification for the sake of convenience, assuming claims are always current rather than a snapshot, and storing overly sensitive data inside the token’s claims.
13Real-World Examples
A few concrete scenarios showing the ID token in action.
Single Sign-On Across Multiple Company Apps
After logging in once, a user’s ID token lets each connected internal application immediately display “Welcome, [name]” without asking the user to log in again.
Single-Page Web Applications
A browser-based app reads the ID token right after login to personalize the interface with the user’s name and profile picture, entirely on the client side.
Mobile Applications
A mobile app uses the ID token to display the logged-in user’s identity locally, while separately using the access token whenever it calls backend services.
Federated Login Through a Partner Company
When a user logs in through an external identity provider brokered by Keycloak, the resulting ID token still gives the application a consistent, standardized way to know who logged in, regardless of which provider was actually used.
14Frequently Asked Questions
No. An ID token proves who the user is, meant for the application itself. An access token grants permission to call APIs on the user’s behalf. They serve different purposes and shouldn’t be used interchangeably.
Yes. The token is signed, not encrypted, so its claims are readable by anyone who has a copy of it — the signature only prevents tampering, not reading. Sensitive secrets should never be placed inside it.
The application should reject it immediately. A mismatched signature means either the token was altered after issuance or it wasn’t actually issued by the expected Keycloak realm.
No. An ID token is a fixed snapshot taken at login time. If a user updates their email or name afterward, the application needs a fresh token — through re-authentication or a new sign-in — to see the updated information.
The audience claim states which specific application the token was intended for, so a token meant for one app can’t be mistakenly (or maliciously) accepted by a completely different one.
Generally not recommended. ID tokens are meant to be short-lived, and storing them long-term risks working with stale identity data and unnecessarily extending how long a leaked token could remain sensitive, even though it will eventually expire.
15Summary and Key Takeaways
An ID token in Keycloak is a signed, self-contained proof of identity, issued the moment a user successfully logs in, built on the OpenID Connect standard, and formatted as a JSON Web Token. It carries a small set of claims — who the user is, who issued the token, which application it’s meant for, and when it expires — all protected by a cryptographic signature that lets any receiving application trust the information without needing to call Keycloak back to double-check. Its clean, singular purpose is to answer “who is this?”, deliberately separate from the access token’s job of controlling API access. Understanding this distinction, and applying the right verification checks every time, is what turns the ID token from a convenient shortcut into a genuinely trustworthy piece of identity infrastructure.
Key Takeaways
- An ID token proves who logged in, not what they can access. — That job belongs to the access token, and the two should never be confused.
- It’s a signed JSON Web Token, following the OpenID Connect standard. — This makes it portable and understood consistently across many platforms, not just Keycloak.
- Its claims — sub, iss, aud, exp, and profile data — describe the login event. — Together, they form a verifiable snapshot of who authenticated, when, and for which application.
- Signed does not mean encrypted. — Anyone can read an ID token’s contents; only tampering is prevented, so sensitive secrets should never be placed inside it.
- Always verify signature, issuer, audience, and expiration. — Skipping any one of these checks defeats the security guarantees the token is meant to provide.
- Claims are a fixed snapshot, not a live feed. — Profile changes made after login won’t appear until a fresh token is issued.
- Never use an ID token to authorize API calls. — That’s the access token’s job; mixing the two up is one of the most common and consequential mistakes beginners make.