mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] AuthCoreProvider: OAuth Support Part 2
This commit is contained in:
parent
d1d3f12abd
commit
d3751732b0
12 changed files with 76 additions and 9 deletions
|
@ -42,7 +42,7 @@ public static void registerProviders() {
|
|||
}
|
||||
public abstract User getUserByUsername(String username);
|
||||
public abstract User getUserByUUID(UUID uuid);
|
||||
public abstract User getUserByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired;
|
||||
public abstract UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired;
|
||||
public abstract AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthResponse.AuthContext context /* may be null */);
|
||||
public abstract void verifyAuth(AuthResponse.AuthContext context) throws AuthException;
|
||||
public abstract PasswordVerifyReport verifyPassword(User user, AuthRequest.AuthPasswordInterface password);
|
||||
|
|
|
@ -59,7 +59,7 @@ public User getUserByUUID(UUID uuid) {
|
|||
}
|
||||
|
||||
@Override
|
||||
public User getUserByOAuthAccessToken(String accessToken) {
|
||||
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public User getUserByUUID(UUID uuid) {
|
|||
}
|
||||
|
||||
@Override
|
||||
public User getUserByOAuthAccessToken(String accessToken) {
|
||||
public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws OAuthAccessTokenExpired {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package pro.gravit.launchserver.auth.core;
|
||||
|
||||
public interface UserSession {
|
||||
String getID();
|
||||
User getUser();
|
||||
long getExpireIn();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package pro.gravit.launchserver.auth.core.interfaces.provider;
|
||||
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.auth.core.UserSession;
|
||||
|
||||
public interface AuthSupportExit {
|
||||
boolean deleteSession(UserSession session);
|
||||
boolean exitUser(User user);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package pro.gravit.launchserver.auth.core.interfaces.provider;
|
||||
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.auth.core.UserSession;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AuthSupportGetSessionsFromUser {
|
||||
List<UserSession> getSessionsByUser(User user);
|
||||
void clearSessionsByUser(User user);
|
||||
}
|
|
@ -86,6 +86,10 @@ public static AuthReport ofOAuthWithMinecraft(String minecraftAccessToken, Strin
|
|||
public static AuthReport ofMinecraftAccessToken(String minecraftAccessToken) {
|
||||
return new AuthReport(minecraftAccessToken, null, null, 0);
|
||||
}
|
||||
|
||||
public boolean isUsingOAuth() {
|
||||
return oauthAccessToken != null || oauthRefreshToken != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +131,7 @@ private String authWithProviderAndHandler(AuthResponse.AuthContext context, Auth
|
|||
uuid = context.pair.handler.usernameToUUID(aresult.username);
|
||||
accessToken = null;
|
||||
}
|
||||
internalAuth(context.client, context.authType, context.pair, username, uuid, aresult.permissions);
|
||||
internalAuth(context.client, context.authType, context.pair, username, uuid, aresult.permissions, false);
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
|
@ -149,7 +153,7 @@ private AuthReport authWithCore(AuthResponse.AuthContext context, AuthRequest.Au
|
|||
throw new AuthException("Internal Auth Error");
|
||||
}
|
||||
context.client.coreObject = user;
|
||||
internalAuth(context.client, context.authType, context.pair, user.getUsername(), uuid, user.getPermissions());
|
||||
internalAuth(context.client, context.authType, context.pair, user.getUsername(), uuid, user.getPermissions(), result.isUsingOAuth());
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
|
@ -168,7 +172,7 @@ private AuthReport authWithCore(AuthResponse.AuthContext context, AuthRequest.Au
|
|||
/**
|
||||
* Writing authorization information to the Client object
|
||||
*/
|
||||
public void internalAuth(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String username, UUID uuid, ClientPermissions permissions) {
|
||||
public void internalAuth(Client client, AuthResponse.ConnectTypes authType, AuthProviderPair pair, String username, UUID uuid, ClientPermissions permissions, boolean oauth) {
|
||||
client.isAuth = true;
|
||||
client.permissions = permissions;
|
||||
client.auth_id = pair.name;
|
||||
|
@ -176,6 +180,7 @@ public void internalAuth(Client client, AuthResponse.ConnectTypes authType, Auth
|
|||
client.username = username;
|
||||
client.type = authType;
|
||||
client.uuid = uuid;
|
||||
client.useOAuth = oauth;
|
||||
if(pair.isUseCore() && client.coreObject == null) {
|
||||
client.coreObject = pair.core.getUserByUUID(uuid);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
public class Client {
|
||||
public UUID session;
|
||||
public boolean useOAuth;
|
||||
public String auth_id;
|
||||
public long timestamp;
|
||||
public AuthResponse.ConnectTypes type;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
import pro.gravit.launchserver.auth.provider.AuthProvider;
|
||||
import pro.gravit.launchserver.auth.provider.AuthProviderDAOResult;
|
||||
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||
import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse;
|
||||
|
@ -59,15 +60,20 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
|||
server.authManager.check(context);
|
||||
password = server.authManager.decryptPassword(password);
|
||||
server.authHookManager.preHook.hook(context, clientData);
|
||||
result.accessToken = server.authManager.auth(context, password);
|
||||
context.report = server.authManager.auth(context, password);
|
||||
server.authHookManager.postHook.hook(context, clientData);
|
||||
if (getSession) {
|
||||
if(context.report.isUsingOAuth()) {
|
||||
result.oauth = new AuthRequestEvent.OAuthRequestEvent(context.report.oauthAccessToken, context.report.oauthRefreshToken, context.report.oauthExpire);
|
||||
} else if (getSession) {
|
||||
if (clientData.session == null) {
|
||||
clientData.session = UUID.randomUUID();
|
||||
//server.sessionManager.addClient(clientData);
|
||||
}
|
||||
result.session = clientData.session;
|
||||
}
|
||||
if(context.report.minecraftAccessToken != null) {
|
||||
result.accessToken = context.report.minecraftAccessToken;
|
||||
}
|
||||
result.playerProfile = ProfileByUUIDResponse.getProfile(clientData.uuid, clientData.username, client, clientData.auth.textureProvider);
|
||||
sendResult(result);
|
||||
} catch (AuthException | HookException e) {
|
||||
|
@ -89,6 +95,7 @@ public static class AuthContext {
|
|||
public final ConnectTypes authType;
|
||||
public final Client client;
|
||||
public final AuthProviderPair pair;
|
||||
public AuthManager.AuthReport report;
|
||||
@Deprecated
|
||||
public int password_length; //Use AuthProvider for get password
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception {
|
|||
sendError("Session invalid");
|
||||
return;
|
||||
}
|
||||
if(rClient[0].useOAuth) {
|
||||
sendError("This session using OAuth. Session restoration not safety");
|
||||
return;
|
||||
}
|
||||
WebSocketFrameHandler frameHandler = ctx.pipeline().get(WebSocketFrameHandler.class);
|
||||
frameHandler.setClient(rClient[0]);
|
||||
if (needUserInfo) {
|
||||
|
|
|
@ -23,6 +23,8 @@ public class AuthRequestEvent extends RequestEvent {
|
|||
public String protectToken;
|
||||
@LauncherNetworkAPI
|
||||
public UUID session;
|
||||
@LauncherNetworkAPI
|
||||
public OAuthRequestEvent oauth;
|
||||
|
||||
public AuthRequestEvent() {
|
||||
}
|
||||
|
@ -48,6 +50,27 @@ public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfi
|
|||
this.session = session;
|
||||
}
|
||||
|
||||
public AuthRequestEvent(ClientPermissions permissions, PlayerProfile playerProfile, String accessToken, String protectToken, UUID session, OAuthRequestEvent oauth) {
|
||||
this.permissions = permissions;
|
||||
this.playerProfile = playerProfile;
|
||||
this.accessToken = accessToken;
|
||||
this.protectToken = protectToken;
|
||||
this.session = session;
|
||||
this.oauth = oauth;
|
||||
}
|
||||
|
||||
public static class OAuthRequestEvent {
|
||||
public final String accessToken;
|
||||
public final String refreshToken;
|
||||
public final long expire;
|
||||
|
||||
public OAuthRequestEvent(String accessToken, String refreshToken, long expire) {
|
||||
this.accessToken = accessToken;
|
||||
this.refreshToken = refreshToken;
|
||||
this.expire = expire;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "auth";
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit 91fad5ac1c650f1a8cd21486b455c666bf143d81
|
||||
Subproject commit 7efafab83a169da634a28b9f0aadb14f512c8f58
|
Loading…
Reference in a new issue