# 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.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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`.
  `static boolean`
  `isNativeAvailable()`
  `true` when a native, OS-level implementation is available on the current platform.
  `static void`
  `setProvider(OidcBrowserNative p)`
  Registers the native `OidcBrowserNative` implementation.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.

  - ### setProvider

    public static void setProvider(OidcBrowserNative p)

    Registers the native `OidcBrowserNative` implementation. Called at app startup by the port (`OidcBrowserNativeImpl.init()`); cn1lib authors can also call this to plug in their own implementation -- for example to wrap a 3rd-party SDK that drives the OS sheet differently. Pass `null` to revert to the `BrowserWindow` fallback.

    Class.forName-based lookup is intentionally avoided because Codename One obfuscates class names; the port instead instantiates the impl itself and passes the instance here.

  - ### 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.