The situation is as follows: where I'm working right now OAuth is used for authentication. I'm building a JavaFX application that will be installed on several user laptops and right now authenticating using OAuth is working when I use the WebView browser that shows the login page of the PKCE flow by calling webEngine.loadContent(response.body().toString());
Other applications used by the same users on the same machines are running in the browser and as the credentials they use are the same for the different applications, Single Sign On is the goal of the organization. That means I would like to switch from using the WebView by throwing the HTML-login page I get returned from the authentication server to the default browser in Windows.
But I don't see a way.
First I found the Document.getDesktop().browse action, but that doesn't work in JavaFX. Application.getHostServices().showDocument is what I found, but that wants an URL as input, where I would like to supply a String, just as with webEngine.loadContent
So, how to open the default browser from JavaFX and hand the HTML document as a String to show as a parameter?
The only thing I found on SO that comes close to what I want and might work is this: Unable to load an html file (from local file system) using JxBrowser But, jxbrowser somehow seems to be in the maven central repo (https://mvnrepository.com/artifact/com.teamdev.jxbrowser/jxbrowser/7.12.2), but actually isn't, 'mvn clean install' can't find it and that seems logical as clicking on the jar / View All from the URL above 404's
As stated in the comments, one approach is to save the HTML string to a file, then browse the file. This will work with either
javafx.application.HostServicesorjava.awt.Desktop.Here's an example:
Note: The above creates a temporary file but makes no attempt to delete it.
Comment the
Destkopline and uncomment thegetHostServices()line to try the other API.Note I tried to use a data URI with the following:
But all I got was a "You'll need a new app to open this data link" popup on Windows 10. Then the only option was to look for an app on the store. I saw the same behavior with
Desktop.