Class SystemBrowser

java.lang.Object
com.codename1.io.oidc.SystemBrowser

public final class SystemBrowser extends Object

Routes an authorization-code-flow sign-in through the system browser (ASWebAuthenticationSession on iOS, an Android Custom Tab on Android, the user's default browser on JavaSE / Web) and resolves with the final redirect URL once the OS hands it back. Replaces the embedded WebView approach used by the legacy Oauth2 class.

You normally do not call this directly --

invalid reference
OidcClient.authorize
does it

for you. Use the public methods on this class when wiring up a custom OAuth 2.0 flow that does not fit the OIDC client (e.g. device flow).

Why the system browser?

Modern identity providers (Google Identity Services, Apple, Microsoft Entra ID, Auth0, Firebase Auth) refuse to render their sign-in pages inside an embedded WebView -- it's flagged as a phishing surface and blocked. Using the OS-provided sheet gives the user a trusted UI, preserves cookies for single sign-on, and integrates with password and passkey autofill.

Since:
8.0
  • Method Details

    • isNativeAvailable

      public static boolean isNativeAvailable()
      true when a native, OS-level implementation is available on the current platform. When false the authenticate(String, String) call falls back to an in-app BrowserWindow. Call this if you want to surface a clear UX warning to the user.
    • setNative

      public static void setNative(OidcBrowserNative provider)
      Registers a custom OidcBrowserNative -- for cn1lib authors who want to override the port-provided one, e.g. to wrap a 3rd-party SDK that drives the OS sheet differently. Pass null to revert to the port-provided default.
    • authenticate

      public static AsyncResource<String> authenticate(String authorizationUrl, String redirectUri)

      Launches the system browser at authorizationUrl and resolves with the redirect URL once the user is bounced to a location starting with redirectUri.

      Parameters
      • authorizationUrl: Fully-built authorization-endpoint URL.

      • redirectUri: Redirect URI registered with the authorization server. Both custom-scheme URIs (com.example:/oauth2redirect) and HTTPS URIs are accepted; the latter are recommended on Android 11+ where custom schemes can be hijacked.

      Returns

      An AsyncResource that completes with the redirect URL (including query / fragment) or errors with OidcException on cancellation / failure.