- All Known Implementing Classes:
AndroidBrowserService,DesktopBrowserService,DummyBrowserService,IOSBrowserService
launchExternalBrowser(String).
Example
BrowserService.create().ifPresent(service -> {
service.launchExternalBrowser("https://gluonhq.com/");
});
The service can also be used to perform secure user authentication against a web service
(for instance an OAuth 2.0 / OpenID Connect provider), using an embedded browser, by means of
launchWebAuthentication(String, String, Consumer).
Example
BrowserService.create().ifPresent(service -> {
service.launchWebAuthentication(
"https://my-auth-provider.com/authorize?response_type=token&redirect_uri=myapp://callback",
"myapp",
callbackUrl -> {
if (callbackUrl != null) {
System.out.println("Authenticated, callback: " + callbackUrl);
} else {
System.out.println("Authentication cancelled or failed");
}
});
});
Android Configuration: none
iOS Configuration: none
- Since:
- 3.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<BrowserService> create()Returns an instance ofBrowserService.voidLaunches the user-default browser to show a specified URL.voidlaunchWebAuthentication(String url, String callbackUrlScheme, Consumer<String> callback) Starts a web authentication session that lets the user authenticate against a web service, and delivers the redirect (callback) URL back to the app once the authentication flow completes.
-
Method Details
-
create
Returns an instance ofBrowserService.- Returns:
- An instance of
BrowserService.
-
launchExternalBrowser
Launches the user-default browser to show a specified URL.- Parameters:
url- The URL to load when the browser application opens.- Throws:
IOException- If the URL can't be openedURISyntaxException- If it is not a valid URL string
-
launchWebAuthentication
void launchWebAuthentication(String url, String callbackUrlScheme, Consumer<String> callback) throws IOException, URISyntaxException Starts a web authentication session that lets the user authenticate against a web service, and delivers the redirect (callback) URL back to the app once the authentication flow completes.On iOS this is implemented with a secure, dedicated native web view on top of the app. When the web service redirects to a URL that matches
callbackUrlScheme, the session is automatically dismissed and the full callback URL with the authorization code is passed tocallback. The redirect is secure and never travels through the system URL dispatch.The
callbackUrlSchemecan be provided in two forms:- A custom URL scheme (without
://, e.g."myapp"), with a redirect likemyapp://callback. NoInfo.plistURL scheme registration is required, since the session intercepts the redirect on its own. - A full HTTPS URL (e.g.
"https://example.com/callback"), with a verified HTTPS redirect. This requires iOS 17.4 or higher and the following setup:- The Associated Domains capability enabled on an explicit App ID (a wildcard App ID cannot carry it), and a provisioning profile that grants it.
- The app's entitlements must declare the domain under the
webcredentialsservice type (e.g.webcredentials:example.com). - An
apple-app-site-associationfile hosted athttps://example.com/.well-known/apple-app-site-association(served asapplication/json, no redirects) containing awebcredentialssection that lists the app, e.g.{"webcredentials":{"apps":["TEAMID.bundle.id"]}}. - For local development with a development-signed build (where the file is not on
Apple's CDN), append
?mode=developerto the entitlement domain and enable Settings > Developer > Associated Domains Development on the device.
iOS Configuration: none for the custom-scheme form; the HTTPS form requires the Associated Domains capability and
webcredentialsentitlement described above.On Android and Desktop the default implementation simply opens the URL in the external browser (see
launchExternalBrowser(String)). On Android the redirect is caught by the system through an HTTPS or custom-scheme intent filter declared in theAndroidManifest.xml, and the resulting URL can be read with theRuntimeArgsService.- Parameters:
url- the authentication URL to load, including theredirect_uriexpected by the web service.callbackUrlScheme- either a custom URL scheme (without://, e.g."myapp") or a full HTTPS URL (e.g."https://example.com/callback") that the web service uses for its redirect.callback- a consumer that receives the full callback URL on success, ornullif the user canceled the flow or an error occurred.- Throws:
IOException- If the URL can't be openedURISyntaxException- If it is not a valid URL string- Since:
- 4.0.25
- A custom URL scheme (without
-