Skip to content

[client] add flag to force device code auth - #6885

Open
andreasgerner wants to merge 3 commits into
netbirdio:mainfrom
andreasgerner:feat/device-code-auth
Open

[client] add flag to force device code auth#6885
andreasgerner wants to merge 3 commits into
netbirdio:mainfrom
andreasgerner:feat/device-code-auth

Conversation

@andreasgerner

@andreasgerner andreasgerner commented Jul 24, 2026

Copy link
Copy Markdown

Describe your changes

Add a flag to cli up & login commands to force client to use device code flow.

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

netbirdio/docs#883


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features
    • Added support for device-based authentication during login.
    • Introduced a --use-device-auth flag to drive the same behavior when starting the service.
    • Authentication and SSO OAuth flows now respect the selected device-auth preference, including proper reuse of cached SSO flows.
  • Tests
    • Added unit tests verifying device-flow selection for forced device flow and non-forced desktop behavior.

@CLAassistant

CLAassistant commented Jul 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds --use-device-auth support to login and up commands, carries the setting through LoginRequest, and uses it when creating and reusing OAuth flows. Tests cover forced device-flow selection and desktop behavior.

Changes

Device authentication login

Layer / File(s) Summary
Login request contract and CLI wiring
client/proto/daemon.proto, client/cmd/login.go, client/cmd/up.go
Adds the optional useDeviceAuth request field and wires explicit CLI flags into login request construction.
OAuth flow selection
client/server/server.go, client/cmd/login.go
Passes the requested device-auth setting to OAuth flow creation and requires cached flows to use the same authentication mode.
Device-flow selection tests
client/internal/auth/oauth_test.go
Tests forced device flow and desktop behavior when forcing is disabled.

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

Suggested reviewers: pappz

Sequence Diagram(s)

sequenceDiagram
  participant LoginCommand
  participant LoginRequest
  participant ServerLogin
  participant OAuthFlow
  LoginCommand->>LoginRequest: Set UseDeviceAuth from CLI flag
  LoginRequest->>ServerLogin: Send login request
  ServerLogin->>OAuthFlow: Create or reuse matching auth mode
  OAuthFlow-->>ServerLogin: Select device or browser authentication
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a flag to force device code authentication.
Description check ✅ Passed It covers the change, checklist, docs, and tests; the issue ticket and stack sections are the only omissions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@andreasgerner

Copy link
Copy Markdown
Author

Got no feedback on #6475 after an entire month even tho I even asked some of my colleagues (that also depend on this feature) to upvote it.
Will open this PR to finally get attention to it.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@client/server/server.go`:
- Line 587: Update the OAuth flow reuse logic near auth.NewOAuthFlow to include
msg.GetUseDeviceAuth() in the cached-flow identity, so browser and device-auth
flows with the same client ID are not reused interchangeably. Preserve reuse
only when both the client ID and authentication mode match, or invalidate the
cached flow when the mode changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 19532a32-4194-44f8-be8c-a15d9fdbd837

📥 Commits

Reviewing files that changed from the base of the PR and between b65ec8b and 64804ae.

⛔ Files ignored due to path filters (2)
  • client/proto/daemon.pb.go is excluded by !**/*.pb.go
  • client/proto/daemon_grpc.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (5)
  • client/cmd/login.go
  • client/cmd/up.go
  • client/internal/auth/oauth_test.go
  • client/proto/daemon.proto
  • client/server/server.go

Comment thread client/server/server.go
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
client/server/server.go (1)

626-643: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Cancel the previous pending flow before replacing it.

When the requested auth mode differs from the cached flow, the reuse condition is false and execution proceeds to create a new flow, but s.oauthAuthFlow.waitCancel is not invoked. The old waiter can continue running while s.oauthAuthFlow has already been overwritten with the new flow. Cancel any active previous flow whenever replacing it, including on auth-mode changes.

🤖 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 `@client/server/server.go` around lines 626 - 643, Ensure any active previous
OAuth flow is canceled before creating or assigning a replacement, including
when the requested auth mode differs. Update the flow replacement logic around
s.oauthAuthFlow.waitCancel so cancellation occurs whenever the existing flow
will not be reused, while preserving the current reuse behavior.
🤖 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.

Outside diff comments:
In `@client/server/server.go`:
- Around line 626-643: Ensure any active previous OAuth flow is canceled before
creating or assigning a replacement, including when the requested auth mode
differs. Update the flow replacement logic around s.oauthAuthFlow.waitCancel so
cancellation occurs whenever the existing flow will not be reused, while
preserving the current reuse behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c2b7b72-072e-4385-bc55-840a31e28e23

📥 Commits

Reviewing files that changed from the base of the PR and between 4ae04a8 and 6ee1dbb.

📒 Files selected for processing (1)
  • client/server/server.go

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants