mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
microsoft account server joining
This commit is contained in:
parent
ae8772c6b3
commit
198bea07cb
@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.accounts.Account
|
|||||||
import de.bixilon.minosoft.data.accounts.AccountType
|
import de.bixilon.minosoft.data.accounts.AccountType
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||||
|
import de.bixilon.minosoft.util.account.microsoft.AccountUtil
|
||||||
import de.bixilon.minosoft.util.account.microsoft.MicrosoftOAuthUtils
|
import de.bixilon.minosoft.util.account.microsoft.MicrosoftOAuthUtils
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ class MicrosoftAccount(
|
|||||||
override val type: ResourceLocation = RESOURCE_LOCATION
|
override val type: ResourceLocation = RESOURCE_LOCATION
|
||||||
|
|
||||||
override fun join(serverId: String) {
|
override fun join(serverId: String) {
|
||||||
TODO()
|
AccountUtil.joinMojangServer(username, accessToken!!, uuid, serverId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun logout() {}
|
override fun logout() {}
|
||||||
|
@ -21,8 +21,8 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
|
|||||||
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
import de.bixilon.minosoft.util.KUtil.asResourceLocation
|
||||||
import de.bixilon.minosoft.util.KUtil.asUUID
|
import de.bixilon.minosoft.util.KUtil.asUUID
|
||||||
import de.bixilon.minosoft.util.KUtil.nullCast
|
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||||
import de.bixilon.minosoft.util.KUtil.trim
|
|
||||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||||
|
import de.bixilon.minosoft.util.account.microsoft.AccountUtil
|
||||||
import de.bixilon.minosoft.util.http.HTTP2.postJson
|
import de.bixilon.minosoft.util.http.HTTP2.postJson
|
||||||
import de.bixilon.minosoft.util.http.exceptions.AuthenticationException
|
import de.bixilon.minosoft.util.http.exceptions.AuthenticationException
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -42,19 +42,7 @@ class MojangAccount(
|
|||||||
override val type: ResourceLocation = RESOURCE_LOCATION
|
override val type: ResourceLocation = RESOURCE_LOCATION
|
||||||
|
|
||||||
override fun join(serverId: String) {
|
override fun join(serverId: String) {
|
||||||
val response = mutableMapOf(
|
AccountUtil.joinMojangServer(username, accessToken, uuid, serverId)
|
||||||
"accessToken" to accessToken,
|
|
||||||
"selectedProfile" to uuid.trim(),
|
|
||||||
"serverId" to serverId,
|
|
||||||
).postJson(MOJANG_URL_JOIN)
|
|
||||||
|
|
||||||
|
|
||||||
if (response.statusCode != 204) {
|
|
||||||
response.body!!
|
|
||||||
throw AuthenticationException(response.statusCode, response.body["errorMessage"]?.nullCast())
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.log(LogMessageType.AUTHENTICATION, LogLevels.VERBOSE) { "Mojang server join successful (username=$username, serverId=$serverId)" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun logout() {
|
override fun logout() {
|
||||||
@ -109,7 +97,6 @@ class MojangAccount(
|
|||||||
|
|
||||||
companion object : AccountType(MojangAccount::class) {
|
companion object : AccountType(MojangAccount::class) {
|
||||||
private const val MOJANG_URL_LOGIN = "https://authserver.mojang.com/authenticate"
|
private const val MOJANG_URL_LOGIN = "https://authserver.mojang.com/authenticate"
|
||||||
private const val MOJANG_URL_JOIN = "https://sessionserver.mojang.com/session/minecraft/join"
|
|
||||||
private const val MOJANG_URL_REFRESH = "https://authserver.mojang.com/refresh"
|
private const val MOJANG_URL_REFRESH = "https://authserver.mojang.com/refresh"
|
||||||
private const val MOJANG_URL_INVALIDATE = "https://authserver.mojang.com/invalidate"
|
private const val MOJANG_URL_INVALIDATE = "https://authserver.mojang.com/invalidate"
|
||||||
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:mojang_account".asResourceLocation()
|
override val RESOURCE_LOCATION: ResourceLocation = "minosoft:mojang_account".asResourceLocation()
|
||||||
|
@ -15,10 +15,20 @@ package de.bixilon.minosoft.util.account.microsoft
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.accounts.MojangAccountInfo
|
import de.bixilon.minosoft.data.accounts.MojangAccountInfo
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
|
import de.bixilon.minosoft.util.KUtil.nullCast
|
||||||
|
import de.bixilon.minosoft.util.KUtil.trim
|
||||||
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
import de.bixilon.minosoft.util.KUtil.unsafeCast
|
||||||
import de.bixilon.minosoft.util.http.HTTP2.getJson
|
import de.bixilon.minosoft.util.http.HTTP2.getJson
|
||||||
|
import de.bixilon.minosoft.util.http.HTTP2.postJson
|
||||||
|
import de.bixilon.minosoft.util.http.exceptions.AuthenticationException
|
||||||
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
object AccountUtil {
|
object AccountUtil {
|
||||||
|
private const val MOJANG_URL_JOIN = "https://sessionserver.mojang.com/session/minecraft/join"
|
||||||
|
|
||||||
fun getMojangAccountInfo(bearerToken: String): MojangAccountInfo {
|
fun getMojangAccountInfo(bearerToken: String): MojangAccountInfo {
|
||||||
val response = ProtocolDefinition.MICROSOFT_ACCOUNT_GET_MOJANG_PROFILE_URL.getJson(mapOf(
|
val response = ProtocolDefinition.MICROSOFT_ACCOUNT_GET_MOJANG_PROFILE_URL.getJson(mapOf(
|
||||||
"Authorization" to "Bearer $bearerToken"
|
"Authorization" to "Bearer $bearerToken"
|
||||||
@ -38,4 +48,20 @@ object AccountUtil {
|
|||||||
name = response.body["name"].unsafeCast(),
|
name = response.body["name"].unsafeCast(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun joinMojangServer(username: String, accessToken: String, selectedProfile: UUID, serverId: String) {
|
||||||
|
val response = mutableMapOf(
|
||||||
|
"accessToken" to accessToken,
|
||||||
|
"selectedProfile" to selectedProfile.trim(),
|
||||||
|
"serverId" to serverId,
|
||||||
|
).postJson(MOJANG_URL_JOIN)
|
||||||
|
|
||||||
|
|
||||||
|
if (response.statusCode != 204) {
|
||||||
|
response.body!!
|
||||||
|
throw AuthenticationException(response.statusCode, response.body["errorMessage"]?.nullCast())
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.log(LogMessageType.AUTHENTICATION, LogLevels.VERBOSE) { "Mojang server join successful (username=$username, serverId=$serverId)" }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user