When the Keycloak device authorization grant fits a device without a usable browser
The device authorization grant lets a user approve sign-in on a phone or laptop while the device that needs access, such as a CLI, TV app or kiosk, shows only a short code and a verification address. The device never handles the user's password, and it receives tokens only after the user completes the approval in a browser somewhere else. Teams reach for this flow when a developer, operator or customer must authenticate to a tool that has no keyboard-friendly login page, or when typing credentials on a TV remote or kiosk screen would be unworkable.
The flow suits command-line tools run by developers or operators on workstations and servers that have no display, smart TV and set-top apps, and shared kiosks where the person at the device has a phone. It is a poor fit for devices that can open a normal browser, for anything that needs a non-human identity (the client credentials grant covers service-to-service access), and for applications where the device itself must hold a long-lived session without a human approving each sign-in. Confirm against the Keycloak server administration guide that the device grant is available and configured as you expect in the Keycloak version you run before you commit a design to it.
Compared with a browser redirect flow, the device grant moves more of the work into the design. Your team must decide how the code is shown and how long it stays valid, how the client polls for the token, how it handles slow-down and expiry responses, and how it limits repeated sign-in attempts that could be used to phish users. Those choices sit in client settings and in the client code, so budget time for testing on the real devices, including the behavior when a user abandons the approval halfway through.
Client and realm settings for device sign-in and when each fits
This table compares the Keycloak client and realm choices an administrator makes for a device client, with the situation each option fits and what it changes for the user. Read each row as a decision: pick the option that matches the device's ability to hold a secret and the access it needs. Confirm exact labels and defaults in the server administration guide for your Keycloak version before you configure anything.
| Setting | When it fits | What it changes for the user and operations |
|---|---|---|
| Public versus confidential client | Public client when the CLI or TV app ships to many machines and cannot keep a client secret. Confidential client when a trusted host or kiosk can store a secret safely. | A public client needs no secret, so anyone who copies the binary can call the token endpoint. A confidential client adds secret rotation work but limits who can start a device flow. |
| Device grant only versus broader flows | Device-only when the client exists solely for device sign-in. Broader flows when the same client also serves a browser or other grant types. | A device-only client reduces what an attacker can do with a stolen client identity. Broader flows make the client harder to reason about during reviews. |
| Scopes and default client scopes | Request only the scopes the device needs, such as profile and email for a display name. Add API scopes only when the device calls a specific API. | Fewer scopes mean smaller tokens and a shorter consent or login prompt. Broad scopes show more permissions to the user on the verification page. |
| Audience mappers | Add an audience mapper when APIs behind the device check the aud claim and reject tokens meant for another resource. | Without the mapper, tokens may fail validation at the API. Each new API audience widens what a token can be presented to. |
| Access and refresh token lifetimes | Shorter access tokens and longer refresh lifetimes suit long-running CLIs that must not prompt users often. Shorter session limits suit kiosks in shared rooms. | Longer lifetimes reduce sign-in prompts but keep a lost device valid longer. Shorter lifetimes add refresh traffic and can interrupt unattended tools. |
| Device code and user code lifetime | Set a lifetime long enough for a user to switch to a phone or browser, and short enough to limit guessing and phishing windows. | Users who take too long must restart the flow. Expired codes are a common support cause, so test the time a real user needs. |
| User code format and verification page | Use the default verification page for most deployments. Customize the page only when branding or a clear instruction for the device type is required. | Users type the code on a second device. Customized pages must still show the realm, the client name and the requested access so users can judge the request. |
| Polling interval and abuse controls | Keep the polling interval the server returns and set brute-force protection on the realm for user code entry. | Clients that poll too often get slowed down or fail. Weak limits let attackers try many codes against one pending flow. |
How the device, the user's browser and Keycloak exchange codes
The flow starts on the device, which asks Keycloak's device authorization endpoint for a device code and a user code, then shows the user code and a verification URI on its screen. The user opens that URI in a browser on a separate device, signs in to Keycloak there, and approves the request. Meanwhile the device polls the token endpoint with the device code. Check that the approving browser is a trusted surface, that polling respects the interval Keycloak returns, and that the device code expires.
Device polls Keycloak while the user approves the code in a separate browser.
Setting up the device grant in Keycloak step by step
This sequence takes a team from an existing or new realm to a device client that issues verified tokens with the claims their CLI, TV or kiosk expects. Each step ends with a check so problems surface before a real device is involved.
Choose or create the realm and device client
Decide whether the device client lives in an existing realm used by your other applications or in a dedicated realm for the devices and their users. Create a client for the device workload with the client type your design requires, typically a public client because a CLI or TV app cannot keep a secret. Keep the client separate from your browser and API clients so its settings can change without affecting them. Done when the client appears in the realm's client list with the identifier you documented and you can open its settings page without errors. Menu labels differ between Keycloak versions, so confirm the exact path in the documentation for the version you run.
Enable the device grant on that client only
In the client's capability settings, turn on the OAuth 2.0 device authorization grant for this client and leave it off for every other client in the realm. Record the decision in your configuration notes, since enabling the grant on a broad client widens the set of places a device code can be issued. Confirm the client is still a public client if that is your design, and that no client secret is required for the device flow. Done when a request to the device authorization endpoint for this client returns a device code and user code, and the same request for a client without the grant is refused.
Set redirect, scope and verification settings
Configure the scopes the device needs, such as openid plus any custom scope your APIs require, and assign them as default or optional scopes on the client. Set valid redirect URIs only if your design uses a browser-based step that returns to the device or a verification page, and keep them as narrow as possible. Confirm the verification URI that users open on their phone or laptop is reachable over TLS and is the address your users will see on the device screen. Done when a device authorization request with the scopes you set returns a verification URI and the user code, and the scope list in the token response matches what you configured.
Assign roles and audience mappers
Map the realm or client roles that authorize access to each API, then add an audience mapper so access tokens carry the audience value the API checks. If your APIs validate the token against a resource identifier, add that identifier to the audience claim explicitly rather than relying on defaults. Limit role assignment to the users or groups that need the device capability, and document which group each device type uses. Done when a test user assigned the role receives a token whose audience and role claims match the API's documented requirements, and a user without the role does not.
Test the flow end to end on a real device
Run the flow on the actual hardware or client software your users will use, not only on a developer workstation. Start the device authorization request, display the user code and verification URI, complete login in a browser on a separate device, and watch the device poll the token endpoint until it receives tokens. Note the polling interval the server returns and confirm the device honors it and handles the pending and slow-down responses. Done when the device reaches a signed-in state from a clean start, and a second run after logout succeeds without manual cleanup.
Inspect token claims before release
Decode the access and ID tokens from the test run and compare every claim against your written requirements, including issuer, audience, subject, expiry, scope, roles and any custom claims the device software reads. Check that no unexpected claims carry personal data the device does not need and that token lifetimes match your policy. Repeat the check for a user without the role to confirm the denial path. Done when each required claim is present with the expected value, the issuer matches your realm URL, and the signed-out user cannot reuse the token against the API.
Tuning user codes, device codes and polling intervals
The user code is the short string a person types into the verification page after the device shows it. It controls how quickly someone can complete sign-in on a TV or kiosk without a keyboard-friendly browser. Because it is short and typed by hand, it is also the value an attacker is most likely to guess, so its length, character set and lifetime shape both usability and guessing risk.
- Length and alphabet: Shorter codes with a limited character set are easier to read and type but give an attacker fewer possibilities to exhaust. Confirm the format Keycloak generates in your version.
- Lifetime: A short-lived user code narrows the window for guessing, but it must still be long enough for a person to find a phone and finish the login.
- Attempt limits: Ask whether your version throttles failed or repeated attempts against the verification page and how brute-force protection applies to it.
- Display: Make sure the device shows the code clearly and the verification URL in full, so people do not mistype or enter a code from an unrelated session.
- Phishing exposure: Users can be tricked into entering a code that a third party generated, so the verification page should show which client is asking for access.
Confirm the default code format, lifetime and any throttling settings in the Keycloak server administration guide for your version before you set them.
The device code is a long, opaque value the device keeps and presents when it polls the token endpoint. It is never shown to the user. It links the device's polling loop to the user's approval, so its entropy and lifetime protect the flow from being hijacked. Treat it like a credential held in device memory, even though it is short-lived.
- Entropy: The device code must be unguessable. Do not replace it with a shorter value to make debugging easier.
- Expiry: Once the device code expires, the device can no longer complete sign-in and must restart the flow. Ask Keycloak which lifetime applies to your realm and client.
- Storage: CLIs should keep the device code in memory for the duration of the flow rather than writing it to logs or shell history.
- Single use: Confirm that a device code cannot be redeemed more than once after a successful token issue.
- Client binding: The device code belongs to one client. A code issued to one application must not be usable by another.
Confirm expiry and any related limits for your version in the Keycloak server administration guide before you write retry logic against them.
Polling is how the device learns that the user has approved the request. The token endpoint returns an interval the device must wait between requests. The device must respect that value, because polling faster than allowed is treated as an error and can slow or break the flow for every device sharing the same client and load balancer.
- Honor the returned interval: Wait at least the interval the server returns before the next token request, and read it again from each response rather than hard-coding a value.
- Too-fast polling: A device that polls too quickly receives a slow-down style error. Your client should back off by the increment the specification describes instead of retrying immediately.
- Pending responses: While the user has not yet approved, the server answers with a pending status. This is normal and should not be treated as a failure.
- Expiry responses: After the device code expires, the server reports that the code is no longer valid. The device should stop polling, tell the user, and start a new flow.
- Denial and timeouts: Handle a user denial separately from expiry, and cap total polling time in the device.
Check the interval defaults and any configurable limits in the Keycloak server administration guide for your version, and test with a real device before you go live.
Abuse controls to put in place for device sign-in
Device sign-in moves part of the login into a second browser or session that the user does not control, so attackers aim at the user code, the verification page and the token endpoint. Each card below pairs one abuse path with a Keycloak control and the decisions your team still has to make.
User code phishing on the verification page
An attacker starts a device flow, reads the user code, and asks a victim to enter it on the real verification page, so the victim approves the attacker's CLI session. In Keycloak, the verification page is the normal login page, so require strong authentication there and keep user codes short-lived. Decide how much warning text the verification page shows, which clients may use the flow at all, and whether approvals from unfamiliar locations need a second factor.
Keycloak docsBrute force against the verification page
Attackers can guess user codes or flood the verification page to exhaust the code space or lock out real users. Enable Keycloak's brute force detection in the realm security defenses so repeated failed logins are throttled and temporarily blocked. Test that the lockout thresholds and wait times still allow a legitimate user to retry a mistyped code. Decide the failure threshold and whether lockouts should be permanent or time-limited for shared kiosks.
Polling abuse at the token endpoint
A device client polls the token endpoint at the interval the server returns, and a buggy or hostile client that ignores that interval can add load and hammer the server. Keep the polling interval returned by the device authorization endpoint realistic, and make the client obey slow_down responses by increasing its interval. Monitor token endpoint request rates per client in your metrics. Decide the acceptable request rate per device client and the alert threshold that signals abuse.
Device client secret or public client misuse
A device client that is a confidential client has a secret embedded in every copy of a CLI, which means one leaked binary exposes that secret. A public client avoids the secret but then depends entirely on the user approval step and on tight redirect and scope settings. Choose the client type per application, keep it separate from browser and service clients, and disable grants the device client does not need. Decide who owns client registration and how often client secrets rotate.
Consent and scope creep for devices
Device approvals often happen on a screen that gives the user little context, so a device client can quietly request broad scopes. Limit the device client's default scopes to what the tool needs, and review optional scopes and role mappings before granting them. Check the consent screen wording on the verification page with a real user. Decide which scopes are allowed for device clients, and whether any device client may hold administrative roles at all.
Audit logging of device approvals
Without logs, a suspicious approval leaves no trace of which device, client and account were involved. Enable Keycloak's event logging for login and token events, and forward them to your log platform with retention that matches your investigation needs. Alert on approvals that come from new locations or spikes in device logins. Decide the retention period, who reviews the alerts, and how device logins are tagged so they can be separated from browser logins.
Operating device sign-in after launch
Once device sign-in is live, the work that matters most is watching where it fails. Track failed and expired device logins separately from ordinary password failures, because a rising count of expired device codes usually means users are not finishing the browser step in time, the verification page is slow, or polling is not picking up approval quickly enough. Each device client also generates polling traffic against the token endpoint for as long as a code is pending, so measure token endpoint request rates per client and compare them with the polling interval your CLI or device firmware actually uses. Keycloak can expose Prometheus-format metrics at /metrics on its management interface when started with --metrics-enabled=true, and the optional HTTP request histograms let you see that load next to the rest of your traffic. Confirm the exact metric names and histogram options in the observability guide for your release before you write alert rules against them.
Login failures deserve a retention decision of their own. In the 26.8 release line, the upgrade notes say login failures are persisted to the database by default, so failed device attempts accumulate in your database alongside every other failed login. Decide how long those records must be kept for your investigations and audit needs, set a cleanup schedule that matches that answer, and size the database for the growth. Ask your database team to confirm that the cleanup runs against your production schema without locking tables that the sign-in path depends on. Do this before launch, because the volume from polling-driven failures can be larger than teams expect.
Keep the device client's settings under change control. The grant type, client authentication method, allowed scopes, token lifetimes and the device verification URI all sit in client configuration, and a change to any of them can break every device in the field at once. Store the realm and client definition in version control or your configuration-as-code pipeline, review each Keycloak upgrade against the upgrade notes before rollout, and test device sign-in in a staging realm first. The Keycloak Operator documentation recommends manual approval mode for operator updates, which gives your team a checkpoint to run that test before any upgrade reaches production. Confirm the device grant behavior on the exact version you run, since client policies and defaults can change between releases.
What to confirm in your environment before you commit to the device grant
The device grant touches Keycloak's version, client settings, network path, client libraries and login policy all at once, so a gap in any one of them can block a sign-in flow late in the project. The cards below list what to check against the vendor documentation and your own test environment before you commit the design.
Grant availability in your exact distribution
Confirm that the device authorization grant is enabled and configured the way your team needs in the Keycloak version you will run, whether that is the upstream release or the Red Hat build of Keycloak. Check the release line you plan to deploy against, not only the current release, and record the version in your design. If you run the Red Hat build, confirm its documented feature set separately from upstream, because the supported version may lag the upstream release.
Keycloak docsCode and polling lifetime limits
Confirm the lifetime of device codes and user codes, the minimum polling interval the server returns, and what error the token endpoint sends when a client polls too fast or a code expires. Test these values in a realm that matches production settings. Your CLI and TV clients must handle slow_down and expiry responses, and your support staff need to know how long a user has to complete the browser step.
Verification page branding and localization
Confirm how the verification page that users open in a browser is branded, which theme it uses, and whether its text can be localized for your user languages. Check that the page clearly identifies your organization and the application requesting access, since users type a code from a device screen and a generic page invites phishing. Theme work usually belongs in the same change set as your login theme.
Behavior behind your reverse proxy
Confirm that the verification URI and the complete verification URI Keycloak returns use the public frontend hostname and not an internal address. Test the full flow through the proxy, including path restrictions that may block the device endpoint or the verification page. Confirm that the admin hostname separation in your production setup does not hide endpoints that devices must reach.
Client library support on each device platform
Confirm which OAuth 2.0 device grant libraries your CLI, TV and kiosk platforms support, and whether they handle polling, backoff and token refresh correctly. Many device platforms have no maintained Keycloak-specific library, so you may need to write a small client against the standard endpoints. Test each platform with a real device, since shell, embedded and kiosk runtimes differ in how they store tokens and display codes.
Fit with MFA and session policies
Confirm how your MFA step, passkey policy and session lifetimes apply to the browser step that completes a device sign-in, and whether a device token inherits the session length you expect. Check that refresh token lifetime and revocation behave the way your security team requires for long-lived devices such as kiosks. Record the decision in your access policy before rollout.
Questions teams ask before setting up device sign-in in Keycloak
What does the setup effort for device sign-in in Keycloak depend on?
The effort depends mostly on how many clients will use the device flow, how many user populations and realms are involved, and whether the sign-in must work with your existing identity provider or directory. A single CLI client for employees in one realm is a small, contained change. Multiple tools, customer-facing kiosks, several realms, or federation with Microsoft Entra ID or LDAP add design work for client settings, user code policy, mappers and testing. Abuse controls, such as rate limits, code lifetimes and alerting, also add scope when the endpoint is exposed to the internet. Ask any partner to break the quote down by client count, realm count, device types and whether a security review is included.
Can an internal team set up device sign-in in Keycloak without outside help?
Yes, if the team already runs Keycloak in production and has someone who understands OAuth 2.0 device codes, client configuration and token validation. The Keycloak server administration guide documents the client and realm settings involved, so a capable identity engineer can complete a basic setup. Teams without recent Keycloak operations experience often underestimate the testing on real devices, the polling and error handling in the client, and the abuse review. Outside help is most useful when the internal team needs a second review of the design or a documented test plan before launch.
What does the work need from our own people?
Plan for four roles: a realm owner who approves client registrations, scopes and token lifetimes; an identity engineer who configures the clients and validates tokens in each API; a test device set that matches what users will actually run, such as laptops with several operating systems, a smart TV or a kiosk; and a security reviewer who checks the user code design, rate limits and logging. In small organizations one person may hold more than one role. Agree on these names before the work starts, because approvals and device access often cause the longest delays.
How long does device sign-in setup take, and why does the answer vary?
Duration depends on scope rather than on a standard timeline. A single client in one realm with an existing test environment can move quickly, while several clients, a federated user directory, custom verification pages and device testing across platforms take longer. Each client adds its own registration, scope and polling test. Any figure you receive should be tied to a written scope listing clients, realms, device types, environments and review steps. Ask for the milestones and what counts as done, including the device tests.
What recurs after device sign-in goes live?
Some work is one-time, such as the initial client design and device testing. Other work recurs: Keycloak releases several minor versions a year according to the project's release plan, so you need a regular upgrade check of client behavior and the Keycloak release notes. Monitoring of sign-in failures, token request volume and unusual polling patterns is ongoing, and someone must review abuse signals such as repeated unfinished codes. Client secrets, redirect settings and approved device types also need periodic review. Ask a partner whether upgrades, monitoring and abuse review are part of a retainer or a separate engagement.
What should we check in Keycloak before enabling the device flow?
Confirm that the device authorization grant is enabled only on the clients that need it, that each client has a clear owner and that the realm's token and code lifetimes match your risk tolerance. Check that the verification page is served from the public frontend hostname and that the admin console and Administration REST API stay on a separate hostname or context path, as the Keycloak production guide recommends. Verify that TLS covers every request, that metrics are enabled on the management interface if you monitor sign-in activity, and that your logs record failed and expired device codes. Test polling with the intervals your clients will use, including slow-down responses.
When is an outside partner worth engaging for device sign-in?
An outside partner is worth considering when the device flow touches many clients, several realms, customer-facing devices, or a regulated workload that needs a documented security review. It also helps when your team lacks time to build a test device set or to run abuse testing before launch. DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms in your own infrastructure, and runs security testing that can include the sign-in endpoints. DeployOpen prepares evidence for compliance assessments but does not issue audit reports or certifications. Engagements are fixed-scope, so ask for a written scope before comparing quotes.
How DeployOpen scopes, delivers and supports device sign-in
DeployOpen plans, builds, documents and supports Keycloak device authorization grant flows inside your own infrastructure, so your identity team keeps control of the realm, clients and logs. Each engagement starts from a written scope that names the tools, client types and abuse controls covered.
How we scope
- Inventory the CLIs, TVs and kiosks that need device sign-in, and the Keycloak realms and clients each one will use.
- Agree in writing which device client settings, verification URI, user code rules and polling behavior are in scope.
- Confirm the abuse controls, token lifetimes and logging requirements your security team expects before any build starts.
How we build
- Configure dedicated device clients in your Keycloak realm, with the grant enabled only on the clients that need it.
- Test user code entry, polling intervals, slow_down handling and expiry on each device type you run.
- Apply rate limits, brute-force protection and login failure monitoring, then test those controls against deliberate misuse.
How we hand over
- Deliver a written record of client settings, realm changes, scopes and the reasoning behind each abuse control.
- Provide test results, including the device flows exercised, the failures found and the retests after fixes.
- Walk your operations and security teams through monitoring for device logins, with a runbook for revoking a compromised device.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after the initial handover.
- Plan Keycloak upgrades against the release notes so device flows are rechecked after each minor or major version.
- Confirm with your team who owns client changes, incident response and the retest cycle before the engagement closes.

