Keycloak Token Endpoint

Published
Length
3 min read

Luis Felipe Dias

All posts

You call the keycloak token endpoint by sending user or app credentials over HTTPS. The server checks those details and returns a signed token for your session. Most teams set up this flow to manage central login across many apps. When teams assign broad roles to these tokens, users gain too much power. One token can let an app or person read or change sensitive data everywhere. How the keycloak token endpoint works in practice Keycloak groups users, apps, and roles inside separate workspaces

Keycloak + Token Rotation: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You call the keycloak token endpoint by sending user or app credentials over HTTPS. The server checks those details and returns a signed token for your session. Most teams set up this flow to manage central login across many apps. When teams assign broad roles to these tokens, users gain too much power. One token can let an app or person read or change sensitive data everywhere.

How the keycloak token endpoint works in practice

Keycloak groups users, apps, and roles inside separate workspaces called realms. Each realm exposes its own web address for issuing tokens to users and services. An app sends a post request to this address with its secret or user code. Keycloak checks the credentials against its local database or an external user directory. If the check passes, the server builds and signs a JSON token.

The response usually includes an access token, an ID token, and a refresh token. The access token holds the user roles and group names for permission checks. The ID token tells the client app who logged in during that session. The refresh token lets the app ask for a new token when the first expires. Client apps pass the access token to backend services in their request headers.

Teams choose different grant types based on how the app runs. Web apps with a backend server trade a short login code for a token. Automated scripts and backend services send their own client ID and secret instead. Each grant type hits the same endpoint URL to start a valid session.

Choosing the right token lifespan and role scope

Short token lifespans reduce risk if an attacker steals a token in transit. If an access token lasts five minutes, a stolen token stops working very soon. The app must use its refresh token at the endpoint to stay logged in. Admins can revoke a refresh token right away if a user leaves the team.

Teams also use mappers in Keycloak to control what goes inside each token. A mapper copies user details, like team names or email addresses, into token claims. If you add too many claims, the token grows large and slows down requests. Keep claims small so backend apps only see the roles they need to check.

Keycloak + Token Rotation: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What token login solves and what it leaves open

Central token endpoints solve the problem of scattered user accounts across different systems. Your team gets one place to enforce strong passwords and multi-factor login rules. When someone leaves the company, you disable their account in one central spot. Backend services can trust the token signature without checking a password every single time.

Still, a valid token only proves who logged in at the start. It does not inspect or control what commands a user runs inside a database. Once a service accepts the token, the user can run any query their role allows. A developer with write permissions can drop a table or read raw card numbers. The identity server cannot rewrite emails, phone numbers, or national IDs in query results. It also cannot ask a manager to approve one risky command in real time.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How do I find the token URL for my realm?

You can open the OpenID discovery page for your specific realm in a browser. That JSON page lists the exact web address for requesting tokens in your setup.

Why does the endpoint reject my client request?

Most errors happen when the client ID, secret, or grant setting does not match. Check that your client allows the exact login flow your app tries to use.

Can I revoke an active access token right away?

Signed access tokens stay valid until their short timer runs out on its own. You can end the session in Keycloak to stop the refresh token from working.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.