-
Notifications
You must be signed in to change notification settings - Fork 45
Fix SSO login on ChromeOS by using Device Code Flow #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ChromeOS runs Android apps in a container with separate network namespace, preventing the browser from reaching the localhost callback server used by PKCE flow. This causes "service not available" errors after authentication. Use Device Code Flow on ChromeOS (like Android TV) which uses polling instead of localhost callback. On ChromeOS, also auto-open the browser for a similar UX to PKCE while showing QR dialog as fallback.
📝 WalkthroughWalkthroughAdds device code flow detection and support: new PlatformUtils methods detect ChromeOS and require device-code flow for ChromeOS/Android TV; MainActivity gains a Changes
Sequence DiagramsequenceDiagram
participant MA as MainActivity
participant PU as PlatformUtils
participant PM as PackageManager
participant Auth as AuthHandler
participant QR as QRDialog
participant Browser as Browser
MA->>PU: requiresDeviceCodeFlow(context)
PU->>PU: isAndroidTV(context)?
alt Android TV
PU-->>MA: true
else
PU->>PM: hasSystemFeature("org.chromium.arc" / "org.chromium.arc.device_management")
PM-->>PU: feature result
alt ChromeOS detected
PU-->>MA: true
else
PU-->>MA: false
end
end
alt useDeviceCodeFlow == true
MA->>Auth: initiate device-code auth flow
Auth-->>MA: provide device-code URL
MA->>QR: show QR dialog with code/URL
alt device is not TV
MA->>Browser: try to launch URL in browser
Browser-->>MA: success / error
end
else
MA->>Auth: start standard OAuth flow (URL opener)
end
Auth-->>MA: onLoginSuccess
MA->>MA: run/bind engine with useDeviceCodeFlow flag
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/io/netbird/client/MainActivity.java (1)
185-229: Guard DialogFragment dismissal against state loss after browser launch.The
onLoginSuccess()callback runs on a background thread from the OAuth library and attempts to dismissqrCodeDialog. When the browser is launched viastartActivity, the Activity entersonSaveInstanceState, but the callback may fire after this state is saved (when login completes). Callingdismiss()then throwsIllegalStateException.Wrap the dismiss call with
runOnUiThread()to ensure UI thread execution, checkgetSupportFragmentManager().isStateSaved(), and usedismissAllowingStateLoss()when state has been saved.Proposed fix
`@Override` public void onLoginSuccess() { Log.d(LOGTAG, "onLoginSuccess fired for device code flow."); - if (qrCodeDialog != null && qrCodeDialog.isVisible()) { - qrCodeDialog.dismiss(); - qrCodeDialog = null; - } + if (qrCodeDialog != null && qrCodeDialog.isVisible()) { + runOnUiThread(() -> { + if (getSupportFragmentManager().isStateSaved()) { + qrCodeDialog.dismissAllowingStateLoss(); + } else { + qrCodeDialog.dismiss(); + } + qrCodeDialog = null; + }); + } }
ChromeOS runs Android apps in a container with separate network namespace,
preventing the browser from reaching the localhost callback server used by
PKCE flow. This causes "service not available" errors after authentication.
Use Device Code Flow on ChromeOS (like Android TV) which uses polling
instead of localhost callback. On ChromeOS, also auto-open the browser
for a similar UX to PKCE while showing QR dialog as fallback.
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.