mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
wip remove webview, wip improve msa auth
This commit is contained in:
parent
766b2be97a
commit
feaebc9e16
6
pom.xml
6
pom.xml
@ -298,12 +298,6 @@
|
||||
<version>${javafx.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-web</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xeustechnologies</groupId>
|
||||
<artifactId>jcl-core</artifactId>
|
||||
|
@ -13,29 +13,24 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.eros.main.account.add
|
||||
|
||||
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
||||
import de.bixilon.kutil.http.QueryUtil.fromQuery
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.ErosProfileManager
|
||||
import de.bixilon.minosoft.data.accounts.types.microsoft.MicrosoftAccount
|
||||
import de.bixilon.minosoft.gui.eros.controller.JavaFXWindowController
|
||||
import de.bixilon.minosoft.gui.eros.dialog.ErosErrorReport.Companion.report
|
||||
import de.bixilon.minosoft.gui.eros.main.account.AccountController
|
||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import de.bixilon.minosoft.util.account.microsoft.MicrosoftOAuthUtils
|
||||
import javafx.concurrent.Worker
|
||||
import javafx.fxml.FXML
|
||||
import javafx.scene.web.WebView
|
||||
import javafx.scene.control.TextField
|
||||
import javafx.scene.text.TextFlow
|
||||
import javafx.stage.Modality
|
||||
import java.net.URL
|
||||
|
||||
|
||||
class MicrosoftAddController(
|
||||
private val accountController: AccountController,
|
||||
private val account: MicrosoftAccount? = null,
|
||||
) : JavaFXWindowController() {
|
||||
@FXML private lateinit var webView: WebView
|
||||
@FXML private lateinit var textFX: TextFlow
|
||||
@FXML private lateinit var codeFX: TextField
|
||||
|
||||
|
||||
fun show() {
|
||||
@ -49,44 +44,10 @@ class MicrosoftAddController(
|
||||
super.init()
|
||||
val profile = ErosProfileManager.selected.general.accountProfile
|
||||
|
||||
JavaFXUtil.resetWebView()
|
||||
webView.engine.isJavaScriptEnabled = true
|
||||
webView.isContextMenuEnabled = false
|
||||
webView.engine.loadContent("Loading...")
|
||||
webView.engine.loadWorker.stateProperty().addListener { _, _, new ->
|
||||
if (new == Worker.State.SUCCEEDED) {
|
||||
val location = webView.engine.location
|
||||
if (!location.startsWith("ms-xal-" + ProtocolDefinition.MICROSOFT_ACCOUNT_APPLICATION_ID)) {
|
||||
return@addListener
|
||||
}
|
||||
JavaFXUtil.resetWebView()
|
||||
|
||||
DefaultThreadPool += {
|
||||
try {
|
||||
// ms-xal-00000000402b5328://auth/?code=M.R3_BL2.9c86df10-b29b-480d-9094-d8accb31e4a5
|
||||
val account = MicrosoftOAuthUtils.loginToMicrosoftAccount(URL(location).query.fromQuery()["code"]!!)
|
||||
profile.entries[account.id] = account
|
||||
profile.selected = account
|
||||
JavaFXUtil.runLater { accountController.refreshList() }
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
exception.report()
|
||||
}
|
||||
|
||||
JavaFXUtil.runLater { stage.scene.window.hide() }
|
||||
}
|
||||
}
|
||||
}
|
||||
requestOauthFlowToken()
|
||||
}
|
||||
|
||||
private fun requestOauthFlowToken() {
|
||||
webView.engine.load(ProtocolDefinition.MICROSOFT_ACCOUNT_OAUTH_FLOW_URL)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LAYOUT = "minosoft:eros/main/account/add/microsoft.fxml".toResourceLocation()
|
||||
|
||||
private val TITLE = "minosoft:main.account.add.microsoft.title".toResourceLocation()
|
||||
}
|
||||
}
|
||||
|
@ -90,10 +90,11 @@ object MicrosoftOAuthUtils {
|
||||
"TokenType" to "JWT",
|
||||
).postJson(ProtocolDefinition.MICROSOFT_ACCOUNT_XBOX_LIVE_AUTHENTICATE_URL)
|
||||
|
||||
response.body!!
|
||||
if (response.statusCode != 200) {
|
||||
|
||||
if (response.statusCode != 200 || response.body == null) {
|
||||
throw LoginException(response.statusCode, "Could not authenticate with xbox live token", response.body.toString())
|
||||
}
|
||||
|
||||
return Pair(response.body["Token"].unsafeCast(), response.body["DisplayClaims"].asJsonObject()["xui"].asJsonList()[0].asJsonObject()["uhs"].unsafeCast())
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
|
||||
<!--
|
||||
~ Minosoft
|
||||
~ Copyright (C) 2020-2022 Moritz Zwerger
|
||||
@ -14,8 +13,30 @@
|
||||
~ This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.web.WebView?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml/1" fx:id="root" prefHeight="800.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/16"> <!-- fx:controller="de.bixilon.minosoft.gui.eros.main.account.add.MicrosoftAddController"-->
|
||||
<WebView fx:id="webView" HBox.hgrow="ALWAYS"/>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
<?import javafx.scene.text.TextFlow?>
|
||||
<HBox xmlns:fx="http://javafx.com/fxml/1" fx:id="root" prefHeight="90.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17"> <!-- fx:controller="de.bixilon.minosoft.gui.eros.main.account.add.MicrosoftAddController"-->
|
||||
<GridPane HBox.hgrow="ALWAYS">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="ALWAYS"/>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
</rowConstraints>
|
||||
<TextFlow fx:id="textFX" prefHeight="200.0" prefWidth="200.0">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
|
||||
</GridPane.margin>
|
||||
<Text text="Please open https://microsoft.com/link and enter the following code to proceed with the login:"/>
|
||||
</TextFlow>
|
||||
<TextField fx:id="codeFX" editable="false" promptText="Loading...." GridPane.rowIndex="1">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
</GridPane>
|
||||
</HBox>
|
||||
|
Loading…
x
Reference in New Issue
Block a user