Skip to content

feat(auth): add QR code support for device auth flow#942

Merged
JackZhao10086 merged 6 commits into
mainfrom
feat/auth_qrcode
May 18, 2026
Merged

feat(auth): add QR code support for device auth flow#942
JackZhao10086 merged 6 commits into
mainfrom
feat/auth_qrcode

Conversation

@JackZhao10086

@JackZhao10086 JackZhao10086 commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds QR code support for the device authentication flow, including both image and ASCII QR code display options, with improved login hints optimized for AI agent parsing.

Changes

  • Added QR code support for device auth flow with image display ([cmd/auth/login.go]
  • Added ASCII QR code fallback support for environments without image rendering ([cmd/auth/login.go]
  • Updated login QR code display hints for better AI agent compatibility ([cmd/auth/login_messages.go]

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark auth login command works as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Device-flow login now provides QR codes in both ASCII and base64 PNG formats, shown inline for TTY and wrapped for non-TTY outputs.
    • JSON responses include QR fields and display hints to guide rendering and fallbacks.
  • Documentation / Messages

    • Updated and expanded authentication prompts and non-interactive guidance for interactive, non-interactive, TTY and non-TTY flows.

Review Change Stack

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

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d3fab93-57a4-4dd6-9cb7-8068929996f3

📥 Commits

Reviewing files that changed from the base of the PR and between 10d38a2 and cba34c2.

📒 Files selected for processing (1)
  • cmd/auth/login.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/auth/login.go

📝 Walkthrough

Walkthrough

Adds QR-code generation (ASCII and base64 PNG) to device-flow login output and embeds those QR fields into JSON events; updates text output to show ASCII and base64 QR for non-TTY, and extends localized login messages with QR/agent guidance.

Changes

QR Code Support in Device-Flow Login

Layer / File(s) Summary
QR generation setup: imports and helper
cmd/auth/login.go
Adds encoding/base64 and go-qrcode imports and introduces generateQRCode() to produce ASCII QR and base64 PNG from the verification URL.
JSON output integration with QR codes
cmd/auth/login.go
Adds qr_code_ascii, qr_code_base64, and qr_code_display_hint to --no-wait JSON response (lines 269–277) and to device_authorization event payload (lines 293–298); updates hint wording.
Text and non-TTY output integration
cmd/auth/login.go
Emits ScanQRCode prompt and prints ASCII QR; for non-TTY callers also emits base64 PNG between [BASE64 QR CODE START]/[BASE64 QR CODE END] markers followed by QRCodeDisplayHint (lines 311–325).
Message catalog and localization
cmd/auth/login_messages.go
Extends loginMsg with AgentNoJSONHint and QR/link prompt fields; updates Chinese and English message literals and documents getLoginMsg language inputs.
Inline comments
cmd/auth/login.go
Adds/adjusts comments describing syncLoginUserToProfile and findProfileByName (no behavior changes).

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

  • larksuite/cli#856: Related changes to device-flow login message handling around verification_url presentation.
  • larksuite/cli#933: Related edits to --no-wait --json/agent hint text for device authorization flows.

Suggested Reviewers

  • liangshuo-1
  • albertnusouo
  • yux1a0-63

Poem

🐰 I nibbled a URL and stitched a square,
Pixels patterned with a rabbit’s care.
ASCII whiskers, base64 bright,
Scan the square — don’t type the plight.
Hopping logins, snug and light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: adding QR code support to the device authentication flow.
Description check ✅ Passed The description covers all required sections with appropriate detail: summary explains the motivation, changes list the main modifications, test plan includes verification steps, and related issues are noted.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/auth_qrcode

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 18, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@cba34c25d7e330829e5d47528d62276b1c603eaa

🧩 Skill update

npx skills add larksuite/cli#feat/auth_qrcode -y -g

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/auth/login.go (1)

311-327: ⚡ Quick win

Use the non-TTY message keys in the non-TTY branch.

This branch still prints ScanQRCode/ScanOrOpenLink for all callers, so OpenLinkNonTTY and WaitingForScanNonTTY never appear for agent/non-TTY flows.

♻️ Proposed refactor
-		fmt.Fprintf(f.IOStreams.ErrOut, msg.ScanQRCode)
+		if f.IOStreams.IsTerminal {
+			fmt.Fprintf(f.IOStreams.ErrOut, msg.ScanQRCode)
+		} else {
+			fmt.Fprintf(f.IOStreams.ErrOut, msg.OpenLinkNonTTY)
+		}
 		qrCodeASCII, qrCodeBase64 := generateQRCode(authResp.VerificationUriComplete)
 		fmt.Fprint(f.IOStreams.ErrOut, qrCodeASCII)
 		if !f.IOStreams.IsTerminal {
 			if qrCodeBase64 != "" {
 				fmt.Fprintf(f.IOStreams.ErrOut, "[BASE64 QR CODE START]\n")
 				fmt.Fprintf(f.IOStreams.ErrOut, "%s\n", qrCodeBase64)
 				fmt.Fprintf(f.IOStreams.ErrOut, "[BASE64 QR CODE END]\n")
 				fmt.Fprintf(f.IOStreams.ErrOut, "%s\n", msg.QRCodeDisplayHint)
 			}
 		}
 		fmt.Fprintln(f.IOStreams.ErrOut)
-		fmt.Fprintf(f.IOStreams.ErrOut, msg.ScanOrOpenLink)
+		if f.IOStreams.IsTerminal {
+			fmt.Fprintf(f.IOStreams.ErrOut, msg.ScanOrOpenLink)
+		}
 		fmt.Fprintf(f.IOStreams.ErrOut, "  %s\n\n", authResp.VerificationUriComplete)
+		if !f.IOStreams.IsTerminal {
+			fmt.Fprintln(f.IOStreams.ErrOut, msg.WaitingForScanNonTTY)
+		}
 		fmt.Fprintln(f.IOStreams.ErrOut, msg.AgentTimeoutHint)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/auth/login.go` around lines 311 - 327, The non-TTY branch is still using
the interactive message keys (msg.ScanQRCode and msg.ScanOrOpenLink) so agents
never see the non-TTY messages; update the conditional around
f.IOStreams.IsTerminal in the login output block (the area that calls
generateQRCode(authResp.VerificationUriComplete) and prints
qrCodeASCII/qrCodeBase64) to print msg.OpenLinkNonTTY and
msg.WaitingForScanNonTTY instead of msg.ScanQRCode/msg.ScanOrOpenLink when
!f.IOStreams.IsTerminal, while preserving the base64 QR output and the
VerificationUriComplete; ensure the TTY path still uses
msg.ScanQRCode/msg.ScanOrOpenLink and that the non-TTY branch uses the correct
non-TTY message keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/auth/login.go`:
- Around line 311-327: The non-TTY branch is still using the interactive message
keys (msg.ScanQRCode and msg.ScanOrOpenLink) so agents never see the non-TTY
messages; update the conditional around f.IOStreams.IsTerminal in the login
output block (the area that calls
generateQRCode(authResp.VerificationUriComplete) and prints
qrCodeASCII/qrCodeBase64) to print msg.OpenLinkNonTTY and
msg.WaitingForScanNonTTY instead of msg.ScanQRCode/msg.ScanOrOpenLink when
!f.IOStreams.IsTerminal, while preserving the base64 QR output and the
VerificationUriComplete; ensure the TTY path still uses
msg.ScanQRCode/msg.ScanOrOpenLink and that the non-TTY branch uses the correct
non-TTY message keys.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2a289737-2071-41e6-8965-23bd798e8551

📥 Commits

Reviewing files that changed from the base of the PR and between 4b721c0 and f0897e9.

📒 Files selected for processing (2)
  • cmd/auth/login.go
  • cmd/auth/login_messages.go

@JackZhao10086 JackZhao10086 changed the title Feat/auth qrcode feat(auth): add QR code support for device auth flow May 18, 2026
@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.49%. Comparing base (7bad9f2) to head (cba34c2).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #942      +/-   ##
==========================================
+ Coverage   65.92%   66.49%   +0.56%     
==========================================
  Files         523      562      +39     
  Lines       49694    51895    +2201     
==========================================
+ Hits        32760    34506    +1746     
- Misses      14134    14499     +365     
- Partials     2800     2890      +90     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JackZhao10086
JackZhao10086 merged commit 7af616b into main May 18, 2026
21 checks passed
@JackZhao10086
JackZhao10086 deleted the feat/auth_qrcode branch May 18, 2026 12:17
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
* feat(auth): add QR code support for device auth flow

* docs: update login QR code display hints for AI agent

* feat(auth): add ASCII QR code support for auth flow

* docs: add comments for login and auth helper functions

* chore: remove unused qrCodeToBase64 helper function

* fix(auth/login): clarify verification_url handling in login hint
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
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