I am currently developing a small application which allows users to login using one of their social platforms. I have already implemented OpenId login using Facebook and Google which work great. The problem started when I tried implementing it using Microsoft.
Firstly I had to upgrade to Java 13 as I'm using OpenJDK as it was failing an integrity check which got resolved in OpenJDK java 13.
Now I am facing the issue of not being able to log in as cookies are being blocked by Javafx Webview. I have used this answer Setting a cookie using JavaFX's WebEngine/WebView but without luck.
The respone to the following request https://login.live.com/oauth20_authorize.srf?scope=openid&client_id=""&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf
is
https://login.live.com/cookiesDisabled.srf uaid=3745b6b82c9a41ecac8f145573df4d9c&mkt=EN-US&lc=1033
public void microsoftLogin(){
WebView webview = new WebView();
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(anchorPane.getScene().getWindow());
stage.initStyle(StageStyle.UTILITY);
stage.setScene(new Scene(webview));
stage.sizeToScene();
Oauth2 microsoftLogin = new Oauth2().setURL("https://login.live.com/oauth20_authorize.srf")
.addScope("openid")
.setRedirectUri("https://login.live.com/oauth20_desktop.srf")
.setClientId("05f57f35-f90e-4478-ab29-50a838eabdce")
.setResponseType("code")
.build();
try {
Map<String, List<String>> headers = new LinkedHashMap<>();
headers.put("Set-Cookie", Arrays.asList());
java.net.CookieHandler.getDefault().put(URI.create("https://login.live.com"), headers);
if(webview.getEngine().getLoadWorker().getState() == Worker.State.READY) {
webview.getEngine().load(microsoftLogin.toString());
webview.getEngine().locationProperty().addListener((observableValue, s, t1) -> {
System.out.println(t1);
System.out.println(GoogleAccess.cookies().getCookieStore().getCookies().toString());
});
}
}catch (IOException exception){
exception.printStackTrace();
}
stage.show();
}
Has anyone faced this problem already? I'm thinking of dropping login with Microsoft altogether but don't want to limit my users to just Facebook and Goole which I'm pretty sure covers most users anyways