Skip to content

[client] Add Auth.Stop() to cancel an in-progress interactive login#6486

Open
pappz wants to merge 1 commit into
mainfrom
fix/ios-auth-stop-cancel
Open

[client] Add Auth.Stop() to cancel an in-progress interactive login#6486
pappz wants to merge 1 commit into
mainfrom
fix/ios-auth-stop-cancel

Conversation

@pappz

@pappz pappz commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

The iOS PKCE login runs in the main-app process, decoupled from the network extension (the extension's client context is torn down on login-required, which would otherwise kill the WaitToken goroutine before the OAuth callback arrives). Because it is decoupled, nothing aborted the flow when the user dismissed the browser without logging in: WaitToken kept its loopback HTTP server bound to the redirect port until the flow expired, so the next connect stalled trying to bind the same port.

Make the Auth context cancellable and add Auth.Stop(), which cancels it. Cancelling unblocks WaitToken, whose deferred server.Shutdown frees the port immediately. This mirrors how Android's stopEngine() aborts login via the engine context.

NewAuthWithConfig now also derives a cancellable context; its only iOS caller uses LoginSync (no interactive server), so behaviour is unchanged there.

Describe your changes

Issue ticket number and link

Stack

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:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features
    • Added the ability to cancel in-progress authentication flows. Users can now abort interactive login operations on-demand for improved control over the authentication process.

The iOS PKCE login runs in the main-app process, decoupled from the network
extension (the extension's client context is torn down on login-required, which
would otherwise kill the WaitToken goroutine before the OAuth callback arrives).
Because it is decoupled, nothing aborted the flow when the user dismissed the
browser without logging in: WaitToken kept its loopback HTTP server bound to the
redirect port until the flow expired, so the next connect stalled trying to bind
the same port.

Make the Auth context cancellable and add Auth.Stop(), which cancels it. Cancelling
unblocks WaitToken, whose deferred server.Shutdown frees the port immediately. This
mirrors how Android's stopEngine() aborts login via the engine context.

NewAuthWithConfig now also derives a cancellable context; its only iOS caller uses
LoginSync (no interactive server), so behaviour is unchanged there.
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8068e076-7755-4a71-a9b5-abb086165ff7

📥 Commits

Reviewing files that changed from the base of the PR and between 58c79f5 and ef0601b.

📒 Files selected for processing (1)
  • client/ios/NetBirdSDK/login.go

📝 Walkthrough

Walkthrough

The Auth struct in client/ios/NetBirdSDK/login.go gains a cancel context.CancelFunc field. NewAuth and NewAuthWithConfig now create cancellable contexts via context.WithCancel and store the resulting cancel function. A new exported Stop() method invokes that cancel function to abort an in-progress interactive login.

Changes

iOS SDK Auth Cancellation

Layer / File(s) Summary
Auth cancel field, constructor updates, and Stop() method
client/ios/NetBirdSDK/login.go
Auth struct adds cancel context.CancelFunc; NewAuth and NewAuthWithConfig derive cancellable contexts and store the cancel func; new Stop() method calls the stored cancel func when set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 Hippity-hop, the login shall stop,
A cancel func tucked in a cozy struct slot.
When auth runs long and the user says "nay,"
Just call Stop() and whisk it away!
The context is cancelled, the goroutine freed—
A graceful abort is all that we need. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding Auth.Stop() to cancel interactive login flows, which is the primary objective of this PR.
Description check ✅ Passed The description comprehensively explains the problem, solution, and implementation details, and properly completes the required template sections including bug fix classification and documentation decision.
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 fix/ios-auth-stop-cancel

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.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Release artifacts

Built for PR head ef0601b in workflow run #16057.

Artifact Link
All release artifacts Download
Linux packages Download
Windows packages Download
macOS packages Download
UI artifacts Download
UI macOS artifacts Download

GHCR images (amd64)

No GHCR images were pushed.

This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy.

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.

1 participant