Class SystemBrowser
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
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 Summary
Modifier and TypeMethodDescriptionstatic AsyncResource<String> authenticate(String authorizationUrl, String redirectUri) Launches the system browser atauthorizationUrland resolves with the redirect URL once the user is bounced to a location starting withredirectUri.static booleantruewhen a native, OS-level implementation is available on the current platform.static voidsetNative(OidcBrowserNative provider) Registers a customOidcBrowserNative-- for cn1lib authors who want to override the port-provided one, e.g.
-
Method Details
-
isNativeAvailable
public static boolean isNativeAvailable()truewhen a native, OS-level implementation is available on the current platform. Whenfalsetheauthenticate(String, String)call falls back to an in-appBrowserWindow. Call this if you want to surface a clear UX warning to the user. -
setNative
Registers a customOidcBrowserNative-- 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. Passnullto revert to the port-provided default. -
authenticate
Launches the system browser at
authorizationUrland resolves with the redirect URL once the user is bounced to a location starting withredirectUri.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
AsyncResourcethat completes with the redirect URL (including query / fragment) or errors withOidcExceptionon cancellation / failure. -
-