Skip to content

feat(auth): read --device-code from stdin with '-' - #2932

Open
atcommgroup wants to merge 1 commit into
larksuite:mainfrom
atcommgroup:feat/device-code-stdin
Open

atcommgroup wants to merge 1 commit into
larksuite:mainfrom
atcommgroup:feat/device-code-stdin

Conversation

@atcommgroup

@atcommgroup atcommgroup commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

auth login --device-code <code> puts the device code — a bearer secret for the pending authorization — on the command line, where /proc/<pid>/cmdline exposes it to every process of the same user (including sandboxed agent runtimes that share the OS user). This adds --device-code -, which reads the code from stdin instead. Behaviour without - is unchanged.

Changes

  • cmd/auth/login.go: when --device-code is -, read exactly one code from IOStreams.In (surrounding whitespace trimmed, max 4 KiB, any inner Unicode whitespace rejected) before the existing device-code polling path; otherwise return a typed ValidationError (invalid_argument, param --device-code).
  • Flag help mentions "-" reads it from stdin.
  • cmd/auth/login_device_code_stdin_test.go: unit test for the reader (accepted/rejected inputs incl. \v, \f, NBSP; typed error metadata) and an end-to-end --no-wait → --device-code - login through httpmock, including scope-cache cleanup.

Test Plan

  • Unit tests pass (go test ./cmd/auth/, make unit-test, make vet, make fmt-check, go mod tidy unchanged; golangci-lint --new-from-rev and go run -C lint . --changed-from report no issues)
  • Manual local verification on a local build: auth login --help shows the new flag text; malformed stdin (printf 'a b\n' | lark-cli auth login --device-code -) returns the invalid_argument validation envelope without any network call. The successful redeem path is covered by the httpmock end-to-end test above.

Related Issues

  • None

Summary by CodeRabbit

  • New Features
    • auth login --device-code now accepts - to read a device code from standard input. Surrounding whitespace is trimmed, and invalid or oversized input is rejected.

The device code is a bearer secret for the pending authorization. As an argv value it is visible
in /proc/<pid>/cmdline to every process of the same user, including sandboxed agent runtimes.
'--device-code -' reads it from stdin instead; any whitespace inside the code is rejected.
Behaviour without '-' is unchanged.
@CLAassistant

CLAassistant commented Nov 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The auth login --device-code option now accepts - to read a device code from stdin. The command trims and validates the input before continuing the device-code login flow.

Changes: Stdin device-code login

Layer / File(s) Summary
Read, validate, and use stdin device codes
cmd/auth/login.go, cmd/auth/login_device_code_stdin_test.go
The command reads up to 4096 bytes from stdin when --device-code is -. It trims surrounding whitespace and rejects invalid input. Tests cover validation and a completed login, including clearing the requested-scope cache.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant authLoginRun
  participant stdin
  participant DeviceAuthorization
  participant Token
  participant UserInfo
  participant RequestedScopeCache
  authLoginRun->>stdin: Read code when --device-code is "-"
  stdin-->>authLoginRun: Return trimmed code
  authLoginRun->>DeviceAuthorization: Resume device-code polling
  authLoginRun->>Token: Request token
  authLoginRun->>UserInfo: Request user info
  authLoginRun->>RequestedScopeCache: Clear requested-scope cache
Loading

Suggested reviewers: liangshuo-1

Merge Risk: Minimal · up to 983ab

This adds an opt-in way to supply the device code through stdin and leaves existing behavior unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title follows the conventional commit format and names the main change: --device-code now accepts - to read the code from stdin. The changeset adds this flag value, the stdin reader with valid…
Description check Passed The description follows the repository template. It has a Summary that states the motivation (keeping the bearer code out of /proc//cmdline) and scope. It lists the changes per file. The Test Pla…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title follows the conventional commit format and names the main change: --device-code now accepts - to read the code from stdin. The changeset adds this flag value, the stdin reader with validation, and tests for both. The title is specific and matches the changes.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary that states the motivation (keeping the bearer code out of /proc/<pid>/cmdline) and scope. It lists the changes per file. The Test Plan has checkboxes for unit tests and a manual verification item. It also reports a local manual check on the lark-cli flow with a malformed-stdin example, which is related to the template item but does not exercise the lark-cli <domain> <command> flow exactly. Related Issues is set to None, which matches the template.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe23c4e8-a37a-4121-8d88-66dcccd6a269
Commits

Reviewing files that changed from the base of the PR and between c5fbf1a and 983abde.

Files selected for processing: 2

  • cmd/auth/login.go
  • cmd/auth/login_device_code_stdin_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants