2021-05-16 16:07:44 +03:00
|
|
|
package pro.gravit.launchserver.manangers;
|
|
|
|
|
2021-09-25 13:40:08 +03:00
|
|
|
import io.jsonwebtoken.JwtParser;
|
|
|
|
import io.jsonwebtoken.Jwts;
|
2021-05-16 16:07:44 +03:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import pro.gravit.launcher.ClientPermissions;
|
|
|
|
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
2021-05-28 15:13:16 +03:00
|
|
|
import pro.gravit.launcher.profiles.ClientProfile;
|
|
|
|
import pro.gravit.launcher.profiles.PlayerProfile;
|
2021-05-16 16:07:44 +03:00
|
|
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
|
|
|
import pro.gravit.launcher.request.auth.password.*;
|
|
|
|
import pro.gravit.launchserver.LaunchServer;
|
|
|
|
import pro.gravit.launchserver.auth.AuthException;
|
|
|
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
|
|
|
import pro.gravit.launchserver.auth.core.AuthCoreProvider;
|
2021-05-28 15:13:16 +03:00
|
|
|
import pro.gravit.launchserver.auth.core.AuthSocialProvider;
|
2021-05-16 16:07:44 +03:00
|
|
|
import pro.gravit.launchserver.auth.core.User;
|
2021-05-23 13:17:56 +03:00
|
|
|
import pro.gravit.launchserver.auth.core.UserSession;
|
2021-05-28 15:13:16 +03:00
|
|
|
import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportTextures;
|
|
|
|
import pro.gravit.launchserver.auth.texture.TextureProvider;
|
2021-05-16 16:07:44 +03:00
|
|
|
import pro.gravit.launchserver.socket.Client;
|
|
|
|
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
2021-09-25 13:40:08 +03:00
|
|
|
import pro.gravit.launchserver.socket.response.auth.RestoreResponse;
|
2021-05-16 16:07:44 +03:00
|
|
|
import pro.gravit.utils.helper.IOHelper;
|
|
|
|
import pro.gravit.utils.helper.SecurityHelper;
|
|
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
public class AuthManager {
|
|
|
|
private transient final LaunchServer server;
|
|
|
|
private transient final Logger logger = LogManager.getLogger();
|
2021-09-25 13:40:08 +03:00
|
|
|
private transient final JwtParser checkServerTokenParser;
|
2021-05-16 16:07:44 +03:00
|
|
|
|
|
|
|
public AuthManager(LaunchServer server) {
|
|
|
|
this.server = server;
|
2021-09-25 13:40:08 +03:00
|
|
|
this.checkServerTokenParser = Jwts.parserBuilder()
|
|
|
|
.requireIssuer("LaunchServer")
|
|
|
|
.require("tokenType", "checkServer")
|
|
|
|
.setSigningKey(server.keyAgreementManager.ecdsaPublicKey)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String newCheckServerToken(String serverName, String authId) {
|
|
|
|
return Jwts.builder()
|
|
|
|
.setIssuer("LaunchServer")
|
|
|
|
.claim("serverName", serverName)
|
|
|
|
.claim("authId", authId)
|
|
|
|
.claim("tokenType", "checkServer")
|
|
|
|
.signWith(server.keyAgreementManager.ecdsaPrivateKey)
|
|
|
|
.compact();
|
|
|
|
}
|
|
|
|
|
|
|
|
public record CheckServerTokenInfo(String serverName, String authId) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public CheckServerTokenInfo parseCheckServerToken(String token) {
|
|
|
|
try {
|
|
|
|
var jwt = checkServerTokenParser.parseClaimsJws(token).getBody();
|
|
|
|
return new CheckServerTokenInfo(jwt.get("serverName", String.class), jwt.get("authId", String.class));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 14:46:07 +03:00
|
|
|
public static class CheckServerVerifier implements RestoreResponse.ExtendedTokenProvider {
|
|
|
|
private final LaunchServer server;
|
|
|
|
|
|
|
|
public CheckServerVerifier(LaunchServer server) {
|
|
|
|
this.server = server;
|
|
|
|
}
|
2021-09-25 13:40:08 +03:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean accept(Client client, AuthProviderPair pair, String extendedToken) {
|
2021-09-25 14:46:07 +03:00
|
|
|
var info = server.authManager.parseCheckServerToken(extendedToken);
|
2021-09-25 13:40:08 +03:00
|
|
|
if(info == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
client.auth_id = info.authId;
|
|
|
|
client.auth = server.config.getAuthProviderPair(info.authId);
|
|
|
|
if(client.permissions == null) client.permissions = new ClientPermissions();
|
2021-10-13 16:01:12 +03:00
|
|
|
client.permissions.addPerm("launchserver.checkserver");
|
2021-10-17 12:53:33 +03:00
|
|
|
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
2021-09-25 13:40:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create AuthContext
|
2021-05-25 12:17:29 +03:00
|
|
|
*
|
2021-05-16 16:07:44 +03:00
|
|
|
* @return AuthContext instance
|
|
|
|
*/
|
|
|
|
public AuthResponse.AuthContext makeAuthContext(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String login, String profileName, String ip) {
|
|
|
|
Objects.requireNonNull(client, "Client must be not null");
|
|
|
|
Objects.requireNonNull(authType, "authType must be not null");
|
|
|
|
Objects.requireNonNull(pair, "AuthProviderPair must be not null");
|
|
|
|
return new AuthResponse.AuthContext(client, login, profileName, ip, authType, pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate auth params ans state
|
2021-05-25 12:17:29 +03:00
|
|
|
*
|
2021-05-16 16:07:44 +03:00
|
|
|
* @param context Auth context
|
|
|
|
* @throws AuthException auth not possible
|
|
|
|
*/
|
|
|
|
public void check(AuthResponse.AuthContext context) throws AuthException {
|
|
|
|
if (context.authType == AuthResponse.ConnectTypes.CLIENT && !context.client.checkSign) {
|
2021-09-22 08:45:48 +03:00
|
|
|
throw new AuthException("Don't skip Launcher Update");
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
|
|
|
if (context.client.isAuth) {
|
2021-09-22 08:45:48 +03:00
|
|
|
throw new AuthException("You are already logged in");
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Full client authorization with password verification
|
2021-05-25 12:17:29 +03:00
|
|
|
*
|
|
|
|
* @param context AuthContext
|
2021-05-16 16:07:44 +03:00
|
|
|
* @param password User password
|
|
|
|
* @return Access token
|
|
|
|
*/
|
2021-05-22 22:46:31 +03:00
|
|
|
public AuthReport auth(AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password) throws AuthException {
|
2021-05-16 16:07:44 +03:00
|
|
|
AuthCoreProvider provider = context.pair.core;
|
|
|
|
provider.verifyAuth(context);
|
2021-09-22 08:19:18 +03:00
|
|
|
if (password instanceof AuthOAuthPassword password1) {
|
2021-05-23 13:17:56 +03:00
|
|
|
UserSession session;
|
|
|
|
try {
|
|
|
|
session = provider.getUserSessionByOAuthAccessToken(password1.accessToken);
|
|
|
|
} catch (AuthCoreProvider.OAuthAccessTokenExpired oAuthAccessTokenExpired) {
|
|
|
|
throw new AuthException(AuthRequestEvent.OAUTH_TOKEN_EXPIRE);
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
if (session == null) {
|
2021-05-23 13:17:56 +03:00
|
|
|
throw new AuthException(AuthRequestEvent.OAUTH_TOKEN_INVALID);
|
|
|
|
}
|
|
|
|
User user = session.getUser();
|
|
|
|
context.client.coreObject = user;
|
|
|
|
context.client.sessionObject = session;
|
|
|
|
internalAuth(context.client, context.authType, context.pair, user.getUsername(), user.getUUID(), user.getPermissions(), true);
|
2021-05-25 12:17:29 +03:00
|
|
|
if (context.authType == AuthResponse.ConnectTypes.CLIENT && server.config.protectHandler.allowGetAccessToken(context)) {
|
2021-05-23 13:17:56 +03:00
|
|
|
return AuthReport.ofMinecraftAccessToken(user.getAccessToken());
|
|
|
|
}
|
|
|
|
return AuthReport.ofMinecraftAccessToken(null);
|
|
|
|
}
|
2021-05-25 17:44:25 +03:00
|
|
|
User user = null;
|
2021-05-28 15:13:16 +03:00
|
|
|
boolean skipPasswordCheck = false;
|
|
|
|
String login = context.login;
|
|
|
|
if (context.pair.social != null) {
|
|
|
|
AuthSocialProvider.SocialResult result = context.pair.social.preAuth(context, password);
|
|
|
|
if (result != null) {
|
|
|
|
if (result.user != null) user = result.user;
|
|
|
|
if (result.login != null) login = result.login;
|
|
|
|
if (result.password != null) password = result.password;
|
|
|
|
if (result.user != null && result.password == null) skipPasswordCheck = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (user == null && login != null) {
|
2021-05-25 17:44:25 +03:00
|
|
|
user = provider.getUserByLogin(context.login);
|
|
|
|
if (user == null) {
|
|
|
|
throw new AuthException(AuthRequestEvent.USER_NOT_FOUND_ERROR_MESSAGE);
|
|
|
|
}
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
2021-05-28 15:13:16 +03:00
|
|
|
AuthCoreProvider.PasswordVerifyReport report = null;
|
|
|
|
if (!skipPasswordCheck) {
|
|
|
|
report = provider.verifyPassword(user, password);
|
|
|
|
}
|
|
|
|
if (skipPasswordCheck || report.success) {
|
2021-05-22 22:46:31 +03:00
|
|
|
AuthReport result;
|
|
|
|
try {
|
|
|
|
result = provider.createOAuthSession(user, context, report, context.authType == AuthResponse.ConnectTypes.CLIENT && server.config.protectHandler.allowGetAccessToken(context));
|
|
|
|
} catch (IOException e) {
|
2021-05-25 17:44:25 +03:00
|
|
|
if (e instanceof AuthException) throw (AuthException) e;
|
2021-05-22 22:46:31 +03:00
|
|
|
logger.error(e);
|
|
|
|
throw new AuthException("Internal Auth Error");
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
2021-05-25 17:44:25 +03:00
|
|
|
if (user == null) {
|
|
|
|
if (result.session != null) {
|
|
|
|
user = result.session.getUser();
|
|
|
|
} else {
|
|
|
|
logger.error("AuthCoreProvider {} method createOAuthSession returns null session with login null", context.pair.name);
|
|
|
|
throw new AuthException("Internal Auth Error");
|
|
|
|
}
|
|
|
|
}
|
2021-05-16 16:07:44 +03:00
|
|
|
context.client.coreObject = user;
|
2021-05-25 17:44:25 +03:00
|
|
|
internalAuth(context.client, context.authType, context.pair, user.getUsername(), user.getUUID(), user.getPermissions(), result.isUsingOAuth());
|
2021-05-22 22:46:31 +03:00
|
|
|
return result;
|
2021-05-25 12:17:29 +03:00
|
|
|
} else {
|
2021-10-13 17:28:43 +03:00
|
|
|
if (report.needMoreFactors) {
|
2021-05-25 12:17:29 +03:00
|
|
|
if (report.factors.size() == 1 && report.factors.get(0) == -1) {
|
2021-05-16 16:07:44 +03:00
|
|
|
throw new AuthException(AuthRequestEvent.TWO_FACTOR_NEED_ERROR_MESSAGE);
|
|
|
|
}
|
|
|
|
String message = AuthRequestEvent.ONE_FACTOR_NEED_ERROR_MESSAGE_PREFIX
|
|
|
|
.concat(report.factors.stream().map(String::valueOf).collect(Collectors.joining(".")));
|
|
|
|
throw new AuthException(message);
|
|
|
|
}
|
|
|
|
throw new AuthException(AuthRequestEvent.WRONG_PASSWORD_ERROR_MESSAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writing authorization information to the Client object
|
|
|
|
*/
|
2021-05-22 23:22:04 +03:00
|
|
|
public void internalAuth(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String username, UUID uuid, ClientPermissions permissions, boolean oauth) {
|
2021-10-12 12:55:32 +03:00
|
|
|
if(!oauth) {
|
|
|
|
pair.internalShowOAuthWarnMessage();
|
|
|
|
}
|
2021-05-16 16:07:44 +03:00
|
|
|
client.isAuth = true;
|
|
|
|
client.permissions = permissions;
|
|
|
|
client.auth_id = pair.name;
|
|
|
|
client.auth = pair;
|
|
|
|
client.username = username;
|
|
|
|
client.type = authType;
|
|
|
|
client.uuid = uuid;
|
2021-05-22 23:22:04 +03:00
|
|
|
client.useOAuth = oauth;
|
2021-09-22 08:45:48 +03:00
|
|
|
client.coreObject = pair.core.getUserByUUID(uuid);
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
|
|
|
|
2021-05-31 04:25:33 +03:00
|
|
|
public CheckServerReport checkServer(Client client, String username, String serverID) throws IOException {
|
2021-05-25 12:17:29 +03:00
|
|
|
if (client.auth == null) return null;
|
2021-09-22 08:45:48 +03:00
|
|
|
User user = client.auth.core.checkServer(client, username, serverID);
|
|
|
|
if (user == null) return null;
|
|
|
|
else return CheckServerReport.ofUser(user, getPlayerProfile(client.auth, user));
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException {
|
2021-05-25 12:17:29 +03:00
|
|
|
if (client.auth == null) return false;
|
2021-09-22 08:45:48 +03:00
|
|
|
return client.auth.core.joinServer(client, username, accessToken, serverID);
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|
|
|
|
|
2021-05-28 15:13:16 +03:00
|
|
|
public PlayerProfile getPlayerProfile(Client client) {
|
|
|
|
if (client.auth == null) return null;
|
|
|
|
PlayerProfile playerProfile;
|
|
|
|
if (client.useOAuth) {
|
|
|
|
User user = client.getUser();
|
2021-09-12 13:52:10 +03:00
|
|
|
if (user == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-06-15 17:02:33 +03:00
|
|
|
playerProfile = getPlayerProfile(client.auth, user);
|
2021-05-28 15:13:16 +03:00
|
|
|
if (playerProfile != null) return playerProfile;
|
|
|
|
}
|
|
|
|
if (client.auth.textureProvider != null) {
|
|
|
|
return getPlayerProfile(client.uuid, client.username, client.profile == null ? null : client.profile.getTitle(), client.auth.textureProvider);
|
|
|
|
}
|
|
|
|
// Return combined profile
|
|
|
|
return new PlayerProfile(client.uuid, client.username, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerProfile getPlayerProfile(AuthProviderPair pair, String username) {
|
|
|
|
return getPlayerProfile(pair, username, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerProfile getPlayerProfile(AuthProviderPair pair, String username, ClientProfile profile) {
|
2021-09-22 08:45:48 +03:00
|
|
|
UUID uuid;
|
|
|
|
User user = pair.core.getUserByUsername(username);
|
|
|
|
if (user == null) {
|
|
|
|
return null;
|
2021-05-28 15:13:16 +03:00
|
|
|
}
|
2021-09-22 08:45:48 +03:00
|
|
|
PlayerProfile playerProfile = getPlayerProfile(pair, user);
|
|
|
|
uuid = user.getUUID();
|
|
|
|
if (playerProfile != null) return playerProfile;
|
2021-05-28 15:13:16 +03:00
|
|
|
if (uuid == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (pair.textureProvider != null) {
|
|
|
|
return getPlayerProfile(uuid, username, profile == null ? null : profile.getTitle(), pair.textureProvider);
|
|
|
|
}
|
|
|
|
return new PlayerProfile(uuid, username, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerProfile getPlayerProfile(AuthProviderPair pair, UUID uuid) {
|
|
|
|
return getPlayerProfile(pair, uuid, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerProfile getPlayerProfile(AuthProviderPair pair, UUID uuid, ClientProfile profile) {
|
2021-09-22 08:45:48 +03:00
|
|
|
String username;
|
|
|
|
User user = pair.core.getUserByUUID(uuid);
|
|
|
|
if (user == null) {
|
|
|
|
return null;
|
2021-05-28 15:13:16 +03:00
|
|
|
}
|
2021-09-22 08:45:48 +03:00
|
|
|
PlayerProfile playerProfile = getPlayerProfile(pair, user);
|
|
|
|
username = user.getUsername();
|
|
|
|
if (playerProfile != null) return playerProfile;
|
2021-05-28 15:13:16 +03:00
|
|
|
if (username == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (pair.textureProvider != null) {
|
|
|
|
return getPlayerProfile(uuid, username, profile == null ? null : profile.getTitle(), pair.textureProvider);
|
|
|
|
}
|
|
|
|
return new PlayerProfile(uuid, username, null, null);
|
|
|
|
}
|
|
|
|
|
2021-06-15 17:02:33 +03:00
|
|
|
public PlayerProfile getPlayerProfile(AuthProviderPair pair, User user) {
|
2021-05-28 15:13:16 +03:00
|
|
|
if (user instanceof UserSupportTextures) {
|
|
|
|
return new PlayerProfile(user.getUUID(), user.getUsername(), ((UserSupportTextures) user).getSkinTexture(), ((UserSupportTextures) user).getCloakTexture());
|
|
|
|
}
|
2021-09-04 15:53:56 +03:00
|
|
|
if (pair.textureProvider == null) {
|
|
|
|
throw new NullPointerException("TextureProvider not found");
|
|
|
|
}
|
2021-06-15 17:02:33 +03:00
|
|
|
return getPlayerProfile(user.getUUID(), user.getUsername(), "", pair.textureProvider);
|
2021-05-28 15:13:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private PlayerProfile getPlayerProfile(UUID uuid, String username, String client, TextureProvider textureProvider) {
|
|
|
|
// Get skin texture
|
2021-07-27 00:25:04 +03:00
|
|
|
TextureProvider.SkinAndCloakTextures textures = textureProvider.getTextures(uuid, username, client);
|
2021-05-28 15:13:16 +03:00
|
|
|
|
|
|
|
// Return combined profile
|
2021-07-27 00:25:04 +03:00
|
|
|
return new PlayerProfile(uuid, username, textures.skin, textures.cloak);
|
2021-05-28 15:13:16 +03:00
|
|
|
}
|
|
|
|
|
2021-05-16 16:07:44 +03:00
|
|
|
public AuthRequest.AuthPasswordInterface decryptPassword(AuthRequest.AuthPasswordInterface password) throws AuthException {
|
2021-09-22 08:19:18 +03:00
|
|
|
if (password instanceof Auth2FAPassword auth2FAPassword) {
|
2021-05-16 16:07:44 +03:00
|
|
|
auth2FAPassword.firstPassword = tryDecryptPasswordPlain(auth2FAPassword.firstPassword);
|
|
|
|
auth2FAPassword.secondPassword = tryDecryptPasswordPlain(auth2FAPassword.secondPassword);
|
2021-09-22 08:19:18 +03:00
|
|
|
} else if (password instanceof AuthMultiPassword multiPassword) {
|
2021-05-16 16:07:44 +03:00
|
|
|
List<AuthRequest.AuthPasswordInterface> list = new ArrayList<>(multiPassword.list.size());
|
2021-05-25 12:17:29 +03:00
|
|
|
for (AuthRequest.AuthPasswordInterface p : multiPassword.list) {
|
2021-05-16 16:07:44 +03:00
|
|
|
list.add(tryDecryptPasswordPlain(p));
|
|
|
|
}
|
|
|
|
multiPassword.list = list;
|
2021-05-25 12:17:29 +03:00
|
|
|
} else {
|
2021-05-16 16:07:44 +03:00
|
|
|
password = tryDecryptPasswordPlain(password);
|
|
|
|
}
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
|
|
|
private AuthRequest.AuthPasswordInterface tryDecryptPasswordPlain(AuthRequest.AuthPasswordInterface password) throws AuthException {
|
|
|
|
if (password instanceof AuthAESPassword) {
|
|
|
|
try {
|
|
|
|
return new AuthPlainPassword(IOHelper.decode(SecurityHelper.decrypt(server.runtime.passwordEncryptKey
|
|
|
|
, ((AuthAESPassword) password).password)));
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
throw new AuthException("Password decryption error");
|
|
|
|
}
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
if (password instanceof AuthRSAPassword) {
|
2021-05-16 16:07:44 +03:00
|
|
|
try {
|
|
|
|
Cipher cipher = SecurityHelper.newRSADecryptCipher(server.keyAgreementManager.rsaPrivateKey);
|
|
|
|
return new AuthPlainPassword(
|
|
|
|
IOHelper.decode(cipher.doFinal(((AuthRSAPassword) password).password))
|
|
|
|
);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
throw new AuthException("Password decryption error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return password;
|
|
|
|
}
|
2021-05-25 12:17:29 +03:00
|
|
|
|
2021-07-21 19:43:47 +03:00
|
|
|
public static class CheckServerReport {
|
|
|
|
public UUID uuid;
|
|
|
|
public User user;
|
|
|
|
public PlayerProfile playerProfile;
|
|
|
|
|
|
|
|
public CheckServerReport(UUID uuid, User user, PlayerProfile playerProfile) {
|
|
|
|
this.uuid = uuid;
|
|
|
|
this.user = user;
|
|
|
|
this.playerProfile = playerProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CheckServerReport ofUser(User user, PlayerProfile playerProfile) {
|
|
|
|
return new CheckServerReport(user.getUUID(), user, playerProfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CheckServerReport ofUUID(UUID uuid, PlayerProfile playerProfile) {
|
|
|
|
return new CheckServerReport(uuid, null, playerProfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 08:45:48 +03:00
|
|
|
public record AuthReport(String minecraftAccessToken, String oauthAccessToken,
|
|
|
|
String oauthRefreshToken, long oauthExpire,
|
|
|
|
UserSession session) {
|
2021-05-25 12:17:29 +03:00
|
|
|
|
|
|
|
public static AuthReport ofOAuth(String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
|
2021-05-25 13:38:20 +03:00
|
|
|
return new AuthReport(null, oauthAccessToken, oauthRefreshToken, oauthExpire, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AuthReport ofOAuth(String oauthAccessToken, String oauthRefreshToken, long oauthExpire, UserSession session) {
|
|
|
|
return new AuthReport(null, oauthAccessToken, oauthRefreshToken, oauthExpire, session);
|
2021-05-25 12:17:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static AuthReport ofOAuthWithMinecraft(String minecraftAccessToken, String oauthAccessToken, String oauthRefreshToken, long oauthExpire) {
|
2021-05-25 13:38:20 +03:00
|
|
|
return new AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AuthReport ofOAuthWithMinecraft(String minecraftAccessToken, String oauthAccessToken, String oauthRefreshToken, long oauthExpire, UserSession session) {
|
|
|
|
return new AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire, session);
|
2021-05-25 12:17:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static AuthReport ofMinecraftAccessToken(String minecraftAccessToken) {
|
2021-05-25 13:38:20 +03:00
|
|
|
return new AuthReport(minecraftAccessToken, null, null, 0, null);
|
2021-05-25 12:17:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isUsingOAuth() {
|
|
|
|
return oauthAccessToken != null || oauthRefreshToken != null;
|
|
|
|
}
|
|
|
|
}
|
2021-05-16 16:07:44 +03:00
|
|
|
}
|