I had a Swing dialog, which uses JavaFX WebView
to display oAuth 2.0 URL from Google server.
public class SimpleSwingBrowser extends JDialog {
Session cookies for JavaFX WebView are stored in java.net.CookieHandler
.
To manage cookies on your own create new instance of java.net.CookieManager
:
java.net.CookieManager manager = new java.net.CookieManager();
Then set it as default:
java.net.CookieHandler.setDefault(manager);
To clear cookies just call removeAll method:
manager.getCookieStore().removeAll();
or just create new instance of cookie manager and set it as default:
java.net.CookieHandler.setDefault(new java.net.CookieManager());
I used JavaFX 8 WebView to display OAuth 2.0 from Google as well as from Dropbox. Turned out setting a new instance of java.net.CookieManager()
as default worked with Google (and of course removed the session cookies), but I wasn't able to sign in with my Dropbox account anymore. The "Sing in" button just did not work.
I debugged and found out that per default an instance of com.sun.webkit.network.CookieManager
is used. So, I used
java.net.CookieHandler.setDefault(new com.sun.webkit.network.CookieManager());
which solved my problem. Due to its javadoc it's RFC 6265-compliant, which is the current definition of HTTP Cookies and Set-Cookie header fields.
You need to use the JDK (not just the JRE) as your project's system library due to some access restrictions in the JRE.