Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MicrosoftAccount : MinecraftAccount(AccountType.MICROSOFT) {

private var accessToken = ""
private var refreshToken = ""
private var authMethod = AuthMethod.MICROSOFT
private var authMethod = AuthMethod.MINECRAFT_PC

override fun login(): Pair<Session, YggdrasilAuthenticationService> {
if (profile?.uuid == null || accessToken.isEmpty()) {
Expand Down Expand Up @@ -187,10 +187,21 @@ class MicrosoftAccount : MinecraftAccount(AccountType.MICROSOFT) {
/**
* Create a new [MicrosoftAccount] from OAuth
*/
fun buildFromOpenBrowser(handler: OAuthHandler, authMethod: AuthMethod = AuthMethod.AZURE_APP): OAuthServer {
fun buildFromOpenBrowser(handler: OAuthHandler, authMethod: AuthMethod = AuthMethod.LIQUIDBOUNCE): OAuthServer {
return OAuthServer(handler, authMethod).also { it.start() }
}

/**
* Create a new [MicrosoftAccount] from Microsoft Refresh token
*/
fun buildFromRefreshToken(token: String): MicrosoftAccount {
return MicrosoftAccount().also {
it.authMethod = AuthMethod.MINECRAFT_PC
it.refreshToken = token
it.refresh()
}
}

fun replaceKeys(method: AuthMethod, string: String)
= string.replace("<client_id>", method.clientId)
.replace("<redirect_uri>", method.redirectUri)
Expand All @@ -199,18 +210,53 @@ class MicrosoftAccount : MinecraftAccount(AccountType.MICROSOFT) {

enum class AuthMethod(val clientId: String, val redirectUri: String, val scope: String, val rpsTicketRule: String) {

MICROSOFT(
/**
* Official Minecraft auth method.
* It is NOT recommended to be used for production software, however,
* we might need it for testing purposes.
*
* @see https://dreta.dev/blog/2023/08/15/how-minecraft-launchers-work/
*/
MINECRAFT_PC(
"00000000402B5328",
"https://login.live.com/oauth20_desktop.srf",
"service::user.auth.xboxlive.com::MBI_SSL",
"<access_token>"
),

/**
* Official Minecraft Nintendo Switch auth method.
* It is NOT recommended to be used for production software, however,
*we might need it for testing purposes.
*
* @see https://docs.rs/crate/azalea-auth/latest/source/src/auth.rs#285-286
*/
MINECRAFT_NINTENDO_SWITCH(
"00000000441cc96b",
"https://login.live.com/oauth20_desktop.srf",
"service::user.auth.xboxlive.com::MBI_SSL",
"<access_token>"
),

/**
* We registered our own Azure application for LiquidBounce.
* This does not allow email and password authentication; however,
* it is more secure since it forces users to use OAuth.
*/
LIQUIDBOUNCE(
"0add8caf-2cc6-4546-b798-c3d171217dd9",
"http://localhost:${oauthPort}/login",
"XboxLive.signin%20offline_access",
"d=<access_token>"
),

@Deprecated("Replaced by LIQUIDBOUNCE", ReplaceWith("LIQUIDBOUNCE"))
AZURE_APP(
"0add8caf-2cc6-4546-b798-c3d171217dd9",
"http://localhost:${oauthPort}/login",
"XboxLive.signin%20offline_access",
"d=<access_token>"
)
);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ sealed class MinecraftAccount(val type: AccountType) {
fun fromName(name: String): MinecraftAccount {
return if (name.startsWith("ms@")) {
val realName = name.substring(3)
MicrosoftAccount.buildFromAuthCode(realName, MicrosoftAccount.AuthMethod.MICROSOFT)
MicrosoftAccount.buildFromAuthCode(realName, MicrosoftAccount.AuthMethod.MINECRAFT_NINTENDO_SWITCH)
} else {
CrackedAccount(username = name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.util.concurrent.Executors
*/
class OAuthServer(
val handler: MicrosoftAccount.OAuthHandler,
private val authMethod: MicrosoftAccount.AuthMethod = MicrosoftAccount.AuthMethod.AZURE_APP,
private val authMethod: MicrosoftAccount.AuthMethod = MicrosoftAccount.AuthMethod.LIQUIDBOUNCE,
private val httpServer: HttpServer = HttpServer.create(InetSocketAddress("localhost", oauthPort), 0),
private val context: String = "/login"
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package net.ccbluex.liquidbounce.authlib

import com.google.gson.JsonObject
import net.ccbluex.liquidbounce.authlib.account.AlteningAccount
import net.ccbluex.liquidbounce.authlib.account.MicrosoftAccount
import net.ccbluex.liquidbounce.authlib.account.MinecraftAccount
import net.ccbluex.liquidbounce.authlib.account.SessionAccount
import net.ccbluex.liquidbounce.authlib.bantracker.Ban
import net.ccbluex.liquidbounce.authlib.manage.AccountSerializer
import net.ccbluex.liquidbounce.authlib.utils.set
import net.ccbluex.liquidbounce.authlib.utils.toJsonString
import org.junit.jupiter.api.Assertions.assertEquals
Expand Down Expand Up @@ -72,7 +69,7 @@ class AuthLibTests {
override fun authError(error: String) {
println("Auth error: $error")
}
}, MicrosoftAccount.AuthMethod.AZURE_APP)
}, MicrosoftAccount.AuthMethod.LIQUIDBOUNCE)

assertTrue(true)
}
Expand Down