Skip to content

JavaSE: sign in through the default browser with a loopback redirect - #6406

Draft
shannah wants to merge 3 commits into
masterfrom
claude/javase-oidc-loopback-redirect
Draft

shannah wants to merge 3 commits into
masterfrom
claude/javase-oidc-loopback-redirect

Conversation

@shannah

@shannah shannah commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Lets the simulator and desktop apps sign in with OidcClient the way command-line tools do (RFC 8252, section 7.3), instead of in a popup web view. Opt in with OidcClient.setLoopbackRedirectUri("http://127.0.0.1/<path>").

authorize() then works like this:

  1. It listens on 127.0.0.1, on the URI's port, or on one the system picks when the URI names none.
  2. It opens the user's default browser at the authorization URL.
  3. The provider redirects the browser back to http://127.0.0.1:<port>/<path>.

Because the provider's page runs in the user's own browser:

  • passwords, saved credentials and passkeys work;
  • providers that refuse embedded web views work;
  • a provider that hands back by script (location.replace) completes too.

That last case is what the popup BrowserWindow on JavaSE could not finish (see #6404, which fixes the popup for custom-scheme redirects in the meantime).

Changes

  • OidcLoopbackRedirect (new): the service-provider interface a port implements. It is registered through SystemBrowser.setLoopbackProvider, and isLoopbackAvailable() reports whether there is one.
  • OidcClient:
    • setLoopbackRedirectUri accepts only http://127.0.0.1 or http://localhost with an optional port and a path, and no query or fragment.
    • The port the listener bound becomes the redirect URI, in both the authorization request and the token exchange.
    • Cancelling the returned resource closes the listener.
    • A browser that never comes back fails with USER_CANCELLED after ten minutes.
    • Without the opt-in, or on a port with no provider, setRedirectUri is used exactly as before.
    • It is opt-in because some providers refuse a loopback redirect for a client registered as a mobile app.
  • JavaSEOidcLoopbackRedirect (new):
    • A ServerSocket bound to 127.0.0.1 only.
    • It answers the redirect with a "you can close this tab" page ("Sign-in didn't finish" when the provider refused), and returns 404 for anything else.
    • JavaSEPort.init registers it, so the simulator and desktop builds get it. iOS and Android are unchanged.
  • SystemBrowser: its class doc no longer claims JavaSE uses the default browser.
  • Developer guide (Authentication-And-Identity.asciidoc): a short section, "Signing in through the user's own browser on the simulator and desktop".

Tests

  • OidcLoopbackTest (core-unittests):
    • The bound port is the redirect in both the authorization request and the token exchange.
    • A port named in the URI is the one listened on.
    • The state is still checked.
    • A browser that never comes back is cancelled.
    • A listener that cannot bind is a transport error.
    • Cancelling the sign-in stops the listener.
    • Without a loopback provider, the redirect URI is still required.
    • An unsupported provider is not used.
    • Only loopback addresses are accepted.
  • JavaSEOidcLoopbackRedirectTest, on real sockets on 127.0.0.1:
    • The redirect is answered and returned.
    • A refusal says sign-in did not finish.
    • Closing ends the wait, and the wait ends at its timeout.
    • A browser that cannot open is an error.
    • The request head is read up to its blank line and no further.
  • scripts/pre-push-gates.sh --full passes locally, including SpotBugs, PMD, Checkstyle, the guide checks, Vale and the Hugo build. Left to CI: the device and screenshot suites, javadocs (JDK 25) and the guide figure check.

Notes

https://claude.ai/code/session_01SZMcbmyfhDCp3DQ3U1YvWh


Generated by Claude Code

OidcClient.setLoopbackRedirectUri lets the simulator and desktop apps sign
in the way command-line tools do (RFC 8252 section 7.3): authorize() listens
on 127.0.0.1, opens the user's default browser at the authorization URL, and
the provider redirects the browser back to http://127.0.0.1:<port>/<path>.
The provider's page runs in a real browser, so passwords, passkeys and
providers that refuse embedded web views all work, and a provider that hands
back by script (location.replace) completes too.

- OidcLoopbackRedirect: the service-provider interface, registered through
  SystemBrowser.setLoopbackProvider; isLoopbackAvailable reports it.
- OidcClient: the port the listener bound is the redirect in both the
  authorization request and the token exchange. Opt in, because some
  providers refuse a loopback redirect for a client registered as a mobile
  app; elsewhere setRedirectUri is used as before. Cancelling the returned
  resource closes the listener; a browser that never comes back fails with
  USER_CANCELLED after ten minutes.
- JavaSEOidcLoopbackRedirect: a ServerSocket on 127.0.0.1 that answers the
  redirect with a "you can close this tab" page and 404s anything else;
  JavaSEPort.init registers it.
- SystemBrowser's class doc no longer claims JavaSE uses the default browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SZMcbmyfhDCp3DQ3U1YvWh
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SZMcbmyfhDCp3DQ3U1YvWh
@shai-almog

shai-almog commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Compared 12 screenshots: 12 matched.
✅ JavaSE simulator integration screenshots matched stored baselines.

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.

3 participants