The flow breaks when teams ignore that the CLI is holding a bearer token on behalf of a user. If the device code, access token, or refresh token is printed, logged, or copied into scripts, the login becomes a secret distribution path instead of a controlled authentication flow. That is an NHI governance problem, not just an implementation detail.
Why This Matters for Security Teams
Device code login is often adopted because it feels low-friction, but that convenience can hide a control boundary that matters to NHI governance. A CLI is not merely helping a user authenticate; it is temporarily holding a bearer token, and sometimes refresh material, on the user’s behalf. Treating that as a normal convenience feature can turn an authentication flow into a secret distribution path, which then expands the blast radius of logging, scripting, screen sharing, and support tooling. NIST’s NIST Cybersecurity Framework 2.0 places clear emphasis on protecting credentials and managing access outcomes, not just on making login possible.
For NHI-focused teams, the issue is not only whether a token exists, but whether it is being handled like a secret with lifecycle controls. The same pattern appears in broader NHI research, where Ultimate Guide to NHIs shows how often secrets end up in unsafe locations and how rarely organisations fully govern their rotation and revocation. If the CLI is allowed to print or persist device-code-derived tokens, the organisation has effectively created an unmanaged credential channel. In practice, many security teams discover this only after a token has already been copied into a ticket, shell history, or CI job, rather than through intentional design.
How It Works in Practice
A safer implementation starts with a simple assumption: the device code flow is a user-authentication event, but the resulting tokens are secrets that must be handled like any other NHI credential. That means the CLI should suppress token output by default, avoid writing tokens to stdout, and never place access or refresh tokens into debug logs. It should also store secrets in OS-protected storage, apply short TTLs where the identity provider allows it, and revoke or refresh them through controlled paths rather than leaving them available for reuse. For governance teams, this is where Ultimate Guide to NHIs is useful: it frames the broader lifecycle problem, not just the login event.
Practically, security teams should treat the CLI as a workload identity consumer, not as a password manager. The workflow should be designed so that:
- device codes are short-lived and single-purpose;
- access tokens are not printed, copied, or echoed into scripts;
- refresh tokens are stored only in protected credential stores;
- RBAC and PAM policies define what the authenticated user may do after login;
- logs and telemetry redact token material before it reaches SIEM or support channels.
Where possible, pair the flow with stronger runtime controls such as intent-based authorization and policy checks aligned to request context, rather than assuming a one-time login proves ongoing legitimacy. The NIST Cybersecurity Framework 2.0 is useful here because it reinforces identity, access, and protective controls as continuous disciplines, not single-step events. These controls tend to break down in shared terminals, automated scripts, and support workflows because those environments are built to copy output, archive sessions, and re-use commands.
Common Variations and Edge Cases
Tighter token handling often increases friction for developers and operators, so organisations have to balance usability against secret exposure risk. That tradeoff becomes sharper in enterprise CLIs, where users expect headless automation, cached sessions, and non-interactive re-authentication. Current guidance suggests that these cases need explicit policy decisions, because there is no universal standard for how much token persistence is acceptable across every tool and environment.
One common edge case is when a CLI is used inside a script or CI pipeline. If the device-code login is copied into automation, the flow is no longer acting like a human convenience feature; it is functioning as a shared secret bootstrap mechanism. Another edge case is support escalation, where users paste terminal output into chat or issue trackers. That is precisely where token material leaks into places that are outside the original trust boundary. NHI governance research in Ultimate Guide to NHIs shows why secret visibility and offboarding discipline matter, especially when credentials outlive the intended session.
Best practice is evolving toward short-lived credentials, protected storage, and explicit revocation, with the strongest programmes layering in ZTA-style controls and policy enforcement at request time. For organisations that rely on device code login, the right question is not whether the flow is convenient, but whether it creates a repeatable secret-handling pattern that can be audited, rotated, and contained. Where CLIs run in CI/CD, remote shells, or developer container images, the model breaks down because token material is too easy to inherit, snapshot, or reuse across contexts.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST AI RMF set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-03 | Token leakage and weak rotation are classic NHI secret-handling failures. |
| NIST CSF 2.0 | PR.AC-4 | Device-code tokens grant access and need least-privilege handling. |
| NIST AI RMF | Autonomous or scripted login flows need accountable, governed identity decisions. |
Suppress token output, store refresh material securely, and rotate or revoke on a defined schedule.
Related resources from NHI Mgmt Group
- What breaks if an EUDI wallet is treated like a generic login method?
- What breaks when agent access reviews are designed like human access reviews?
- What breaks when identity is treated as an administrative task instead of a control plane?
- Should enterprise agents be treated like service accounts or like users?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on June 6, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org