-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b7ff53
commit 0bca8e3
Showing
17 changed files
with
109 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
server/src/main/java/com/soulfiremc/server/account/MSJavaRefreshTokenAuthService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SoulFire | ||
* Copyright (C) 2024 AlexProgrammerDE | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.soulfiremc.server.account; | ||
|
||
import com.soulfiremc.server.account.service.OnlineChainJavaData; | ||
import com.soulfiremc.server.proxy.SFProxy; | ||
import com.soulfiremc.server.util.LenniHttpHelper; | ||
import net.raphimc.minecraftauth.MinecraftAuth; | ||
import net.raphimc.minecraftauth.step.msa.StepMsaToken; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
public final class MSJavaRefreshTokenAuthService | ||
implements MCAuthService<String, MSJavaRefreshTokenAuthService.MSJavaRefreshTokenAuthData> { | ||
public static final MSJavaRefreshTokenAuthService INSTANCE = new MSJavaRefreshTokenAuthService(); | ||
|
||
private MSJavaRefreshTokenAuthService() {} | ||
|
||
@Override | ||
public CompletableFuture<MinecraftAccount> login(MSJavaRefreshTokenAuthData data, SFProxy proxyData) { | ||
return CompletableFuture.supplyAsync(() -> { | ||
var flow = MinecraftAuth.JAVA_CREDENTIALS_LOGIN; | ||
try { | ||
return AuthHelpers.fromFullJavaSession(AuthType.MICROSOFT_JAVA_REFRESH_TOKEN, flow, flow.getFromInput( | ||
LenniHttpHelper.createLenniMCAuthHttpClient(proxyData), | ||
new StepMsaToken.RefreshToken(data.refreshToken))); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public MSJavaRefreshTokenAuthData createData(String data) { | ||
return new MSJavaRefreshTokenAuthData(data.strip()); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<MinecraftAccount> refresh(MinecraftAccount account, SFProxy proxyData) { | ||
return CompletableFuture.supplyAsync(() -> { | ||
var flow = MinecraftAuth.JAVA_CREDENTIALS_LOGIN; | ||
var fullJavaSession = flow.fromJson(((OnlineChainJavaData) account.accountData()).authChain()); | ||
try { | ||
return AuthHelpers.fromFullJavaSession(AuthType.MICROSOFT_JAVA_REFRESH_TOKEN, flow, flow.refresh( | ||
LenniHttpHelper.createLenniMCAuthHttpClient(proxyData), | ||
fullJavaSession)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean isExpired(MinecraftAccount account) { | ||
var flow = MinecraftAuth.JAVA_CREDENTIALS_LOGIN; | ||
return flow.fromJson(((OnlineChainJavaData) account.accountData()).authChain()).isExpired(); | ||
} | ||
|
||
@Override | ||
public boolean isExpiredOrOutdated(MinecraftAccount account) { | ||
var flow = MinecraftAuth.JAVA_CREDENTIALS_LOGIN; | ||
return flow.fromJson(((OnlineChainJavaData) account.accountData()).authChain()).isExpiredOrOutdated(); | ||
} | ||
|
||
public record MSJavaRefreshTokenAuthData(String refreshToken) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters