无法使用JavaFX WebView JDK12显示Discord OAuth2重定向url

无法使用JavaFX WebView JDK12显示Discord OAuth2重定向url,java,javafx,discord,javafx-webengine,discord-jda,Java,Javafx,Discord,Javafx Webengine,Discord Jda,我正在尝试获取以下站点:在JDK12中加载JavaFXWebView。当我尝试加载该站点时,显示的只是一个白色页面。以下代码用于显示和处理WebView。我正在使用库来处理代码和授权。 DiscordAuth.java: DiscordAuth() 此方法初始化下面代码其余部分中使用的OAuthBuilder getUser(WebView WebView,线程) 这意味着当从Auth URL重定向时,开始检索应用于URL的代码的过程 startOAuth2Flow(WebView-WebV

我正在尝试获取以下站点:在JDK12中加载JavaFXWebView。当我尝试加载该站点时,显示的只是一个白色页面。以下代码用于显示和处理WebView。我正在使用库来处理代码和授权。

DiscordAuth.java:
DiscordAuth()

此方法初始化下面代码其余部分中使用的OAuthBuilder


getUser(WebView WebView,线程)

这意味着当从Auth URL重定向时,开始检索应用于URL的代码的过程


startOAuth2Flow(WebView-WebView,线程)

此方法处理站点重定向以及拆分URL以检索代码。
P.S.重定向到上面列出的验证URL

FXMLController.java:
登录()

当用户按下FXML场景上的登录按钮时,会触发此方法。这意味着允许他们通过JavaFX应用程序登录discord


这是我加载到应用程序时看到的:
机器人:
URL:没有加载到WebEngine的URL
描述:这是运行应用程序时的默认外观。 网址:
描述:这是我单击“注销”时WebView的外观(应该是“登录”,只是忘记更改它)。 [ 网址:
说明:这是按“授权”后显示的白色屏幕。

这是我加载到Chrome时看到的:
网站:
网址:
描述:这是bot应该显示的内容。

这是打印到控制台的信息


再现性:100%
仅尝试在WebView中加载验证url就会导致此问题。
非常感谢您对此事的任何想法。

我发现问题在于[WebView子资源完整性检查在Windows和Linux上失败。 在以下链接中可以看到并证明这一点:


  • 如何解决手头的问题 简言之,问题在于OpenJDK 12 for JavaFX有一个错误,导致Windows和Linux平台上的子资源完整性检查失败,当它没有提供与从获取的资源中获取的哈希匹配的加密哈希时,导致了一个问题。因此,网页的内容将无法正确显示。解决该问题的方法是列表这个bug是在JavaFX13中修补的,所以解决这个问题所需要的就是更新我的maven pom文件中的JavaFX模块

    public DiscordAuth() {
            CLIENT_SECRET = [REDACTED];
            CLIENT_ID = [REDACTED];
            REDIRECT_URL = "https://temperlesergal.github.io/NuBot/discordWebPage/success.html";
             builder = new OAuthBuilder(CLIENT_ID, CLIENT_SECRET)
                    .setScopes(new String[]{"connections", "guilds", "email"})
                    .setRedirectURI(REDIRECT_URL);
        }
    
    public void getUser(WebView webView, Thread thread) {
        startOAuth2Flow(webView, thread);
    }
    
    private void startOAuth2Flow(WebView webView, Thread thread) {
        String authURL = builder.getAuthorizationUrl(null);
        WebEngine webEngine = webView.getEngine();
        webEngine.setJavaScriptEnabled(true);
        webEngine.setUserAgent("Cotton Le Sergal's OAuth2 grant for app.");
        webEngine.getLoadWorker().stateProperty().addListener(
            (ov, oldState, newState) -> {
                if (webEngine.getLoadWorker().getException() != null || newState == Worker.State.FAILED){
                    System.err.println(webEngine.getLoadWorker().getException().toString());
                }else{
                    System.out.println(webEngine.getLoadWorker().getState());
                }
            });
            webEngine.locationProperty().addListener((observableValue, oldLocation, newLocation) -> {
            System.out.println("newLocation = " + newLocation);
            if (newLocation.startsWith(REDIRECT_URL) && newLocation.contains("code")) {
                try {
                    URL url = new URL(newLocation);
                    String[] params = url.getQuery().split("&");
                    Map<String, String> map = new HashMap<>();
                    for (String param : params) {
                        String name = param.split("=")[0];
                        String value = param.split("=")[1];
                        map.put(name, value);
                    }
                    code = map.get("code");
                    gotTheAccessCode(code, thread);
                    System.out.println("Notifying thread");
                    synchronized (thread){
                        thread.notify();
                        thread.start();
                        System.out.println("Thread Notified!");
                    }
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
        });
        String url = "https://temperlesergal.github.io/NuBot/discordWebPage/index.html";
        webEngine.load(url);
    }
    
    private void gotTheAccessCode(String code, Thread thread) {
        System.out.println("access code: " + code);
        Response response = builder.exchange(code);
        if (response == Response.ERROR) {
            // AN ERROR HAPPENED WHILE EXCHANGING THE CODE
        } else {
            // EVERYTHING WORKED AS EXPECTED
        }
        System.out.println("Testing by printing guild info!");
        getGuildInfo().forEach(guild -> System.out.println(guild.getName()));
        System.out.println("DONE!");
        user =  builder.getUser();
        guilds = builder.getGuilds();
        connections = builder.getConnections();
    }
    
    @FXML
    void signIn(){
        Thread thread = new Thread(() -> {
            System.out.println("Thread waking up!");
            Platform.runLater(() -> {
                usernameLabel.setText(discordAuth.getUserNameWithDiscriminator());
                setUserAvatar(discordAuth.getUserAvatarURL());
            });
        });
        try {
            if(thread.isAlive())
                thread.wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        discordSigninWebView.setVisible(true);
        discordSigninWebView.setOpacity(0.0);
        FadeIn signInFade = new FadeIn(discordSigninWebView);
        signInFade.play();
        discordAuth.getUser(discordSigninWebView, thread);
    }
    
    Image size is: 800.0x800.0 with the width being the largest at: 800.0px.
    Image is 8.0 times the size it should be... resizing
    Image has been resized to the following: 100.0x100.0px.
    Actual image size is: 100.0x100.0px.
    Test
    0    [OkHttp https://discordapp.com/...] DEBUG net.dv8tion.jda.internal.requests.Requester  - Received response with following cf-rays: [5176ddc69aaae202-ORD]
    317  [OkHttp https://discordapp.com/...] DEBUG net.dv8tion.jda.internal.requests.Requester  - Received response with following cf-rays: [5176ddc83f13e202-ORD]
    320  [Thread-3] INFO  net.dv8tion.jda.api.JDA  - Login Successful!
    [0 / 3]
    578  [OkHttp https://discordapp.com/...] DEBUG net.dv8tion.jda.internal.requests.Requester  - Received response with following cf-rays: [5176ddca3e3ac510-ORD]
    Host Name: [REDACTED]
    Host Address: [REDACTED]
    693  [JDA [0 / 3] MainWS-ReadThread] INFO  net.dv8tion.jda.internal.requests.WebSocketClient  - Connected to WebSocket
    693  [JDA [0 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Sending Identify-packet...
    734  [JDA [0 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Got HELLO packet (OP 10). Initializing keep-alive.
    754  [OkHttp https://discordapp.com/...] DEBUG net.dv8tion.jda.internal.requests.Requester  - Received response with following cf-rays: [5176ddcaaf3dc510-ORD]
    754  [Thread-3] INFO  net.dv8tion.jda.api.JDA  - Login Successful!
    [1 / 3]
    832  [JDA [0 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.handle.GuildSetupController  - Setting incomplete count to 0
    832  [JDA [0 / 3] MainWS-ReadThread] INFO  net.dv8tion.jda.api.JDA  - Finished Loading!
    Shard: 1 out of: 3 is ready.
    842  [JDA [0 / 3] Gateway-Worker 1] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Sending normal message {"op":3,"d":{"game":{"name":"Type owo.help","type":0},"afk":false,"status":"online","since":1568679123052}}
    883  [OkHttp https://discordapp.com/...] DEBUG net.dv8tion.jda.internal.requests.Requester  - Received response with following cf-rays: [5176ddcc2a44c56c-ORD]
    998  [OkHttp https://discordapp.com/...] DEBUG net.dv8tion.jda.internal.requests.Requester  - Received response with following cf-rays: [5176ddccab8dc56c-ORD]
    998  [Thread-3] INFO  net.dv8tion.jda.api.JDA  - Login Successful!
    [2 / 3]
    5952 [JDA [1 / 3] MainWS-ReadThread] INFO  net.dv8tion.jda.internal.requests.WebSocketClient  - Connected to WebSocket
    5953 [JDA [1 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Sending Identify-packet...
    5955 [JDA [1 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Got HELLO packet (OP 10). Initializing keep-alive.
    6047 [JDA [1 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.handle.GuildSetupController  - Setting incomplete count to 1
    6082 [JDA [1 / 3] MainWS-ReadThread] INFO  net.dv8tion.jda.api.JDA  - Finished Loading!
    Shard: 2 out of: 3 is ready.
    6084 [JDA [1 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.handle.GuildSetupController  - Finished setup for guild 530802775530012672 firing cached events 0
    6246 [JDA [1 / 3] Gateway-Worker 1] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Sending normal message {"op":3,"d":{"game":{"name":"Type owo.help","type":0},"afk":false,"status":"online","since":1568679128295}}
    11239 [JDA [2 / 3] MainWS-WriteThread] INFO  net.dv8tion.jda.internal.requests.WebSocketClient  - Connected to WebSocket
    11240 [JDA [2 / 3] MainWS-WriteThread] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Sending Identify-packet...
    11241 [JDA [2 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Got HELLO packet (OP 10). Initializing keep-alive.
    11368 [JDA [2 / 3] MainWS-ReadThread] DEBUG net.dv8tion.jda.internal.handle.GuildSetupController  - Setting incomplete count to 0
    11368 [JDA [2 / 3] MainWS-ReadThread] INFO  net.dv8tion.jda.api.JDA  - Finished Loading!
    Shard: 3 out of: 3 is ready.
    11504 [JDA [2 / 3] Gateway-Worker 1] DEBUG net.dv8tion.jda.internal.requests.WebSocketClient  - Sending normal message {"op":3,"d":{"game":{"name":"Type owo.help","type":0},"afk":false,"status":"online","since":1568679133581}}
    newLocation = https://temperlesergal.github.io/NuBot/discordWebPage/index.html
    SCHEDULED
    RUNNING
    SUCCEEDED
    newLocation = https://discordapp.com/api/oauth2/authorize?client_id=569662931990478857&redirect_uri=https%3A%2F%2Ftemperlesergal.github.io%2FNuBot%2FdiscordWebPage%2Fsuccess.html&response_type=code&scope=identify%20email%20connections%20guilds
    SCHEDULED
    RUNNING
    newLocation = https://discordapp.com/oauth2/authorize?client_id=569662931990478857&redirect_uri=https%3A%2F%2Ftemperlesergal.github.io%2FNuBot%2FdiscordWebPage%2Fsuccess.html&response_type=code&scope=identify%20email%20connections%20guilds
    SUCCEEDED
    
        Please view link no.1 for more in depth details