Repository navigation
Description
Problem Summary
FoodLens is an open-source AI food intelligence and nutrition platform developed with Flutter. It implements a decentralized User-Pays cloud architecture using Puter.js. Under this model, each user authenticates with their own personal Puter account and consumes their own monthly free AI allowance ($10.00 monthly quota) to run cloud vision inference. This ensures that users own their data and the open-source project maintainer incurs no centralized server costs.
Currently, when a user taps Login or Sign Up in FoodLens, the application displays an embedded WebView inside the Flutter application. This in-app WebView approach creates usability challenges, including lack of access to saved browser passwords, autofill limitations, and inconsistent window handling.
We want both Puter Login and Sign Up actions to open the user default Android external browser (such as Chrome, Firefox, Samsung Internet, or their preferred system browser). After completing authentication in their browser, the user should return to FoodLens with their Puter account session recognized and persisted.
We invite experienced international Flutter, Android, OAuth, and Puter.js developers to investigate this architecture and contribute a verified solution.
Current Behavior vs Expected Behavior
Current Behavior
- The user opens FoodLens and navigates to Onboarding or Profile Settings.
- The user taps Sign In with Puter or Sign Up.
- An internal embedded WebView modal opens within the mobile application.
- The user must authenticate inside this isolated embedded browser instance.
- In-app WebViews lack integration with system-level credential managers and create a suboptimal user experience.
Expected Behavior
- The user taps Sign In with Puter or Sign Up.
- The application opens the user configured default Android browser (or Chrome Custom Tabs if officially supported by the auth provider).
- The user authenticates securely on the official Puter portal using their existing browser session and saved credentials.
- Upon successful authentication, the user is redirected back to the FoodLens mobile application.
- The application securely establishes the user session, verifies their available monthly allowance, and persists the session across app restarts.
Architectural Context and Technical Findings
Current Flutter and JavaScript Bridge Architecture
FoodLens currently communicates with Puter.js through a local headless bridge:
- JavaScript Bridge:
assets/html/puter_bridge.html - Dart Bridge Service:
lib/features/auth/services/puter_bridge_service.dart - In-App WebView Screen:
lib/features/auth/screens/puter_auth_webview_screen.dart - Auth State Provider:
lib/features/auth/providers/auth_provider.dart
Puter.js SDK Investigation
- The official Puter.js SDK (
https://js.puter.com/v2/) relies onputer.auth.signIn(), which is built around browser popup mechanics (window.open). - An external browser session stores authentication cookies within that browser private profile, isolated from the mobile application local storage sandbox.
- Returning from an external browser to an Android native application typically requires Custom URI Schemes (such as
foodlens://auth/callback) or verified Android App Links. - Contributors must research whether Puter officially supports an OAuth 2.0 PKCE redirect flow, a custom redirect URI parameter, or an official mobile SDK integration.
- If the current public Puter.js SDK does not document this flow, contributors are encouraged to research official Puter developer resources or consult the Puter maintainers rather than creating undocumented workarounds.
Strict Security and User-Pays Requirements
Any proposed solution must satisfy the following constraints:
- Preserve User-Pays Model: Every user must authenticate with their own personal Puter account and utilize their own free tier allowance.
- No Insecure Token Exposure: Authentication tokens must never be passed through plain, unencrypted, or logged URL query parameters.
- No Hardcoded Secrets: No developer API keys, secret client keys, or private tokens may be placed in the client application.
- Session Persistence: Once authenticated, the user session must persist across application restarts until explicitly logged out.
Steps to Reproduce Current Implementation
- Connect an Android physical device or start an Android 13+ emulator.
- Clone the repository and run the application:
flutter pub get flutter run
- On the Onboarding screen or Profile Settings, tap Sign in with Puter.
- Notice that an internal embedded WebView is presented instead of launching the system default browser.
Acceptance Criteria
- Both Login and Sign Up buttons launch the user default external browser or an officially supported Custom Tab session.
- After successful authentication on Puter, the user returns smoothly to the FoodLens application.
- The user Puter identity and remaining monthly allowance ($10.00 tier) display correctly in FoodLens.
- The authentication session survives cold application restarts.
- The solution passes
dart format,flutter analyzewith 0 issues, and all automated tests influtter test. - Verified on a physical Android device running API 24+.
How to Contribute
- Review
CONTRIBUTING.mdanddocumentation/AUTHENTICATION_TROUBLESHOOTING.md. - Post a comment on this issue describing your technical approach and findings before writing extensive code.
- Submit a Pull Request targeting the
mainbranch with comprehensive verification notes.
Thank you for contributing to open-source food intelligence.
Activity
docs: link dedicated authentication issue #1 and modernize CI java ac…
[-]Help Wanted: Investigate and Fix Puter.js Authentication and Google Sign-In Integration[/-][+]Help Wanted: Open Puter Login and Sign Up in the External Default Browser[/+]CodeByArnob commentedon Nov 6, 2026
Maintainer investigation: external-browser session handoff
I have verified the current behavior against the official Puter.js documentation and the native-app OAuth security guidance.
Confirmed findings
puter.auth.signIn()is documented as a website-only API. It opens a popup and resolves with aSignInResult.SignInResultincludes an authenticationtoken,app_uid, andusername.https://puter.com/logindirectly in Chrome only authenticates the browser's Puter account. It does not authorize FoodLens as a Puter.js website application and does not create a session in the app's isolated WebView.Proposed implementation direction
isSignedIn(),getUser(), AI access and usage, then test cold restart and sign-out revocation.Maintainer/provider confirmation requested
Can the Puter team confirm whether the public Puter.js website sign-in flow supports a native-app callback / authorization-code exchange (including PKCE), or whether there is a supported secure way for a website's
SignInResult.tokento be delivered to a verified Android Custom Tabs client without exposing it in a redirect URL?Until that provider capability and the trusted callback origin are confirmed, I will not ship an insecure token handoff. The existing PR #4 only opens the generic Puter login page and is not an end-to-end authentication fix.
CodeByArnob commentedon Nov 6, 2026
GitHub Pages origin provisioned
The maintainer has created the public repository
CodeByArnob/CodeByArnob.github.iofor the FoodLens account-connection origin.Remaining setup and security prerequisites
assetlinks.jsonassociation.No token handoff has been implemented or represented as working yet.
CodeByArnob commentedon Nov 6, 2026
Updated authentication compatibility check (November 2026)
I rechecked the current official Puter.js authentication reference.
puter.auth.signIn()is explicitly documented as a website-only popup flow.SignInResultcontaining a bearer-styletoken,app_uid, andusername.Android custom URI schemes can be claimed by another installed app, so we will not pass a Puter token in a custom-scheme URL or query string. We also will not scrape Chrome cookies or treat opening
puter.com/loginas app authorization.Current safe next step
The GitHub Pages origin is deployed, but its page remains a non-authenticating placeholder. We can prepare the Android callback plumbing and test deep-link routing independently, but that alone cannot establish a Puter session. The actual token/session handoff remains blocked until Puter confirms a supported native handoff, or we identify a supported browser-to-app channel that does not expose credentials to other apps.
Please confirm whether Puter supports either:
SignInResult, without placing the token in a URL or clipboard.No insecure callback has been implemented.
CodeByArnob commentedon Nov 6, 2026
Further upstream research: Puter auth popup transport
Additional upstream investigation found Puter issue HeyPuter/puter#1333. It documents that the current sign-in popup relies on
window.openerto communicate its result back to the calling page. A maintainer discussion mentioned a possible WebSocket rendezvous design, but the issue was closed as "not planned" on 2026-03-30. This is not a documented public native SDK or supported Android OAuth contract.The related redirect issue HeyPuter/puter#1965 was closed as a duplicate. The issue page now references Android-related fixes in September 2026, but those references concern dropped-window / hung-page behavior; they do not document a public native redirect URI, PKCE code exchange, or stable app callback contract.
Updated conclusion
postMessageis an Android transport primitive, not proof that Puter's popup will deliver its result to it.Requested upstream confirmation
Please advise whether Puter intends to expose a supported native mobile sign-in API or documented handoff contract (authorization code + PKCE, or an origin-verified message channel). Without that contract, FoodLens cannot truthfully complete automatic native session return using the public SDK alone.
CodeByArnob commentedon Nov 6, 2026
Implementation decision: secure browser-to-app handoff
I verified the current official Puter.js and Android browser contracts before changing the app:
puter.auth.signIn()is a website popup flow. It resolves aSignInResultin the calling web page; the docs do not define an Android redirect URI, authorization-code + PKCE contract, or native SDK callback.Therefore PR #4 remains the safe first step (external browser launch), but it is not yet end-to-end authentication. The remaining blocker is a supported, secure Puter-to-native handoff contract. A zero-backend app cannot securely exchange a one-time opaque code for a Puter session unless Puter provides that native callback or a trusted relay.
I am keeping the existing session/bridge implementation intact until a real end-to-end flow is possible. Acceptance test after the supported handoff exists: sign in and sign up in the device browser, return to FoodLens without pasting a token, verify the Puter user/session, perform an authenticated AI request, force-stop/reopen, and confirm session restoration.
CodeByArnob commentedon Nov 6, 2026
Browser authentication test page is now deployed from the FoodLens Pages repository
Added a dedicated test page at:
https://codebyarnob.github.io/FoodLens/auth-test/
It invokes the documented
puter.auth.signIn({request_auth:true})flow from a user click, then checksputer.auth.getUser(). It displays only the username and never displays, stores, logs, or transmits the session token.What this test proves: Puter browser sign-in can complete on the FoodLens HTTPS origin.
What it does not prove: Android app session handoff or persistence. The public Puter docs still describe a website popup result, not a native Android callback/PKCE contract. I am not marking the app login complete or moving bearer tokens through a deep-link URL.
CodeByArnob commentedon Nov 6, 2026
2026-11-06 implementation audit: secure handoff, encrypted storage, startup validation
I inspected the current
mainimplementation, includingPuterBridgeService,AuthNotifier,LocalStorageService,PuterAuthWebViewScreen, the Android manifest and Gradle configuration.Verified current behavior / issues
AuthNotifier._init()restores a cached user immediately from token + username in local storage, then asynchronously callssetAuthToken()andgetUser(). It does not clear the cached identity if that validation fails. So the startup UI can temporarily (or indefinitely after a failed sync) show a stale signed-in user.LocalStorageServicecurrently persists the Puter bearer token inSharedPreferences, not Android Keystore-backed encrypted storage.PuterAuthWebViewScreenattempts to read authentication cookies and scan Puter WebView localStorage for token-like values. This is not acceptable as the basis for a new external-browser flow and must be retired when the replacement is proven.Secure implementation boundary
The public Puter docs describe
puter.auth.signIn()as a browser popup flow. I have not found a documented native redirect URI, authorization-code + PKCE exchange, or native Android callback contract. Android Custom Tabs postMessage is a browser/app channel, but it requires origin verification and a cooperating web page; it does not automatically make Puter's popup return a native session. We must not send a bearer token in a URL, scrape Chrome storage/cookies, or trust an unverified custom-scheme callback.Work plan
This is an audit and implementation plan, not a claim that the three requested features are already complete.