mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-19 14:33:04 +03:00
maybe its can change something
This commit is contained in:
parent
7fbd668501
commit
749a96a5b9
17 changed files with 238 additions and 200 deletions
|
@ -9,6 +9,11 @@ public AuthProviderResult auth(String login, String password, String ip) {
|
||||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken()); // Same as login
|
return new AuthProviderResult(login, SecurityHelper.randomStringToken()); // Same as login
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthProviderResult oauth(int i) throws Exception {
|
||||||
|
return new AuthProviderResult(String.valueOf(i), SecurityHelper.randomStringToken()); // Same as login
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|
|
@ -28,6 +28,8 @@ public static void registerProviders() {
|
||||||
|
|
||||||
public abstract AuthProviderResult auth(String login, String password, String ip) throws Exception;
|
public abstract AuthProviderResult auth(String login, String password, String ip) throws Exception;
|
||||||
|
|
||||||
|
public abstract AuthProviderResult oauth(int i) throws Exception;
|
||||||
|
|
||||||
public void preAuth(String login, String password, String customText, String ip) {
|
public void preAuth(String login, String password, String customText, String ip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,11 @@ else if (result.error != null)
|
||||||
return authError("Authentication server response is malformed");
|
return authError("Authentication server response is malformed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthProviderResult oauth(int i) throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// pass
|
// pass
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
public final class MySQLAuthProvider extends AuthProvider {
|
public final class MySQLAuthProvider extends AuthProvider {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
private String query;
|
private String query;
|
||||||
|
private String oauthQuery;
|
||||||
private String message;
|
private String message;
|
||||||
private String[] queryParams;
|
private String[] queryParams;
|
||||||
private boolean usePermission;
|
private boolean usePermission;
|
||||||
|
@ -44,6 +45,21 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthProviderResult oauth(int i) throws Exception {
|
||||||
|
try (Connection c = mySQLHolder.getConnection()) {
|
||||||
|
PreparedStatement s = c.prepareStatement(oauthQuery);
|
||||||
|
String[] replaceParams = {"%i%", String.valueOf(i)};
|
||||||
|
s.setString(1, oauthQuery.replace("?", String.valueOf(i)));
|
||||||
|
// Execute SQL query
|
||||||
|
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||||
|
try (ResultSet set = s.executeQuery()) {
|
||||||
|
return set.next() ? new AuthProviderResult(set.getString(1),
|
||||||
|
SecurityHelper.randomStringToken(),
|
||||||
|
LaunchServer.server.config.permissionsHandler.getPermissions(set.getString(1))) : authError(message);
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
mySQLHolder.close();
|
mySQLHolder.close();
|
||||||
|
|
|
@ -13,6 +13,11 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
||||||
return getProvider().auth(login, password, ip);
|
return getProvider().auth(login, password, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthProviderResult oauth(int i) throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
AuthProvider provider = this.provider;
|
AuthProvider provider = this.provider;
|
||||||
|
|
|
@ -30,6 +30,11 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
||||||
return authError(message);
|
return authError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthProviderResult oauth(int i) throws Exception {
|
||||||
|
return authError(message);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|
|
@ -36,6 +36,11 @@ public AuthProviderResult auth(String login, String password, String ip) throws
|
||||||
authError(currentResponse);
|
authError(currentResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthProviderResult oauth(int i) throws Exception {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|
|
@ -86,10 +86,10 @@ public static void registerCommands(ru.gravit.utils.command.CommandHandler handl
|
||||||
service.registerCommand("component", new ComponentCommand(server));
|
service.registerCommand("component", new ComponentCommand(server));
|
||||||
service.registerCommand("givePermission", new GivePermissionsCommand(server));
|
service.registerCommand("givePermission", new GivePermissionsCommand(server));
|
||||||
service.registerCommand("getPermissions", new GetPermissionsCommand(server));
|
service.registerCommand("getPermissions", new GetPermissionsCommand(server));
|
||||||
|
service.registerCommand("cache", new OAuthCacheHandler(server));
|
||||||
|
service.registerCommand("token", new OAuthTokenGet(server));
|
||||||
Category serviceCategory = new Category(service, "service", "Managing LaunchServer Components");
|
Category serviceCategory = new Category(service, "service", "Managing LaunchServer Components");
|
||||||
handler.registerCategory(serviceCategory);
|
handler.registerCategory(serviceCategory);
|
||||||
|
|
||||||
service.registerCommand("cache", new OAuthCacheHandler(server));
|
|
||||||
service.registerCommand("token", new OAuthTokenGet(server));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,10 @@ public String getUsageDescription() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
LogHelper.subInfo("Length of Cache " + OAuthManager.stageAreaLength());
|
LogHelper.subInfo("Length of Cache " + OAuthManager.getCacheLength());
|
||||||
for(int i=0; i < OAuthManager.stageAreaLength(); i++ ){
|
for(OAuthManager.Entry e: OAuthManager.getStageArea() ){
|
||||||
LogHelper.subInfo("IP is: " + LaunchServer.server.cacheHandler.stageArea[i].IP());
|
if(e.isInit())
|
||||||
|
LogHelper.subInfo("IP is: " + e.getIP());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,23 +39,24 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
String code = args[0];
|
String code = args[0];
|
||||||
UserAuthResponse authResponse = mToken(code, vk);
|
UserAuthResponse authResponse = null;
|
||||||
|
try {
|
||||||
|
authResponse = mToken(code, vk);
|
||||||
LogHelper.subInfo(authResponse.getAccessToken());
|
LogHelper.subInfo(authResponse.getAccessToken());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserAuthResponse mToken(String code, VkApiClient vk) {
|
public static UserAuthResponse mToken(String code, VkApiClient vk) throws ClientException, ApiException {
|
||||||
UserAuthResponse authResponse= null;
|
UserAuthResponse authResponse;
|
||||||
try {
|
|
||||||
authResponse = vk.oAuth().
|
authResponse = vk.oAuth().
|
||||||
userAuthorizationCodeFlow(LaunchServer.server.config.OAuthAppID,
|
userAuthorizationCodeFlow(
|
||||||
|
LaunchServer.server.config.OAuthAppID,
|
||||||
LaunchServer.server.config.OAuthAppSecret,
|
LaunchServer.server.config.OAuthAppSecret,
|
||||||
LaunchServer.server.config.getOAuthBackURL(),
|
LaunchServer.server.config.getOAuthBackURL(),
|
||||||
code).execute();
|
code).execute();
|
||||||
} catch (ApiException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ClientException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return authResponse;
|
return authResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package ru.gravit.launchserver.manangers;
|
package ru.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import com.vk.api.sdk.actions.OAuth;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import ru.gravit.launcher.NeedGarbageCollection;
|
import ru.gravit.launcher.NeedGarbageCollection;
|
||||||
|
import ru.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
@ -16,136 +17,138 @@ public class OAuthManager implements NeedGarbageCollection {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void garbageCollection() {
|
public void garbageCollection() {
|
||||||
for(int i=0; i < 5; i++ )
|
for(Entry e: LaunchServer.server.cacheHandler.stageArea)
|
||||||
{
|
{
|
||||||
LaunchServer.server.cacheHandler.stageArea[i].destroy.run();
|
e.destroy();
|
||||||
int finalI = i;
|
|
||||||
LaunchServer.server.cacheHandler.stageArea[i].destroy = new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if(!LaunchServer.server.cacheHandler.stageArea[finalI].init)
|
|
||||||
return;
|
|
||||||
LogHelper.debug("cache purged, IP: " + LaunchServer.server.cacheHandler.stageArea[finalI].IP());
|
|
||||||
LaunchServer.server.cacheHandler.stageArea[finalI].init = false;
|
|
||||||
LaunchServer.server.cacheHandler.stageArea[finalI].mTimer = null;
|
|
||||||
LaunchServer.server.cacheHandler.stageArea[finalI].client = null;
|
|
||||||
LaunchServer.server.cacheHandler.stageArea[finalI].ctx = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
LogHelper.subInfo("OAuthCache purged");
|
LogHelper.subInfo("OAuthCache purged");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entry[] stageArea;
|
|
||||||
|
|
||||||
public OAuthManager(){
|
|
||||||
if(stageArea == null) {
|
|
||||||
stageArea = newEntryArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Entry{
|
public static class Entry{
|
||||||
|
|
||||||
public void setEntry(Client client, ChannelHandlerContext ctx){
|
public void setter(ChannelHandlerContext ctx, Client client){
|
||||||
if(client != null && ctx != null) {
|
|
||||||
this.init = true;
|
this.init = true;
|
||||||
this.client = client;
|
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.mTimer = new Timer();
|
this.client = client;
|
||||||
this.mTimer.schedule(destroy, 300000L);
|
new Timer().schedule(new TimerTask() {
|
||||||
LogHelper.subDebug("New Entry with IP " + IP());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Entry(){
|
|
||||||
this.init = false;
|
|
||||||
this.mTimer = null;
|
|
||||||
this.client = null;
|
|
||||||
this.ctx = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean init = false;
|
|
||||||
|
|
||||||
private Client client = null;
|
|
||||||
|
|
||||||
private ChannelHandlerContext ctx = null;
|
|
||||||
|
|
||||||
private Timer mTimer = null;
|
|
||||||
|
|
||||||
public String IP(){
|
|
||||||
return IOHelper.getIP(getCtx().channel().remoteAddress());
|
|
||||||
}
|
|
||||||
|
|
||||||
private TimerTask destroy = new TimerTask() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if(!init)
|
destroy();
|
||||||
return;
|
}
|
||||||
LogHelper.debug("cache purged, IP: " + IP());
|
}, 300000L);
|
||||||
init = false;
|
}
|
||||||
mTimer = null;
|
|
||||||
client = null;
|
public void setter(AuthRequestEvent authRequestEvent){
|
||||||
ctx = null;
|
this.authRequestEvent = authRequestEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entry(){
|
||||||
|
this.init = false;
|
||||||
|
this.ctx = null;
|
||||||
|
this.client = null;
|
||||||
|
this.authRequestEvent = null;
|
||||||
|
new Timer().cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean init;
|
||||||
|
|
||||||
|
private ChannelHandlerContext ctx;
|
||||||
|
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
private AuthRequestEvent authRequestEvent;
|
||||||
|
|
||||||
|
public void destroy(){
|
||||||
|
this.init = false;
|
||||||
|
this.ctx = null;
|
||||||
|
this.client = null;
|
||||||
|
this.authRequestEvent = null;
|
||||||
|
new Timer().cancel();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public boolean isInit() {
|
public boolean isInit() {
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client getClient() {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelHandlerContext getCtx() {
|
public ChannelHandlerContext getCtx() {
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Client getClient() {
|
||||||
|
return client;
|
||||||
}
|
}
|
||||||
public static int stageAreaLength(){
|
|
||||||
|
public String getIP(){
|
||||||
|
if(isInit())
|
||||||
|
return IOHelper.getIP(getCtx().channel().remoteAddress());
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Entry[] stageArea;
|
||||||
|
|
||||||
|
public static Entry[] getStageArea(){
|
||||||
|
return LaunchServer.server.cacheHandler.stageArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getCacheLength(){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(int e=0; e < 5; e++ )
|
for(Entry e : LaunchServer.server.cacheHandler.stageArea)
|
||||||
{
|
i = e.isInit() ? 1 : 0;
|
||||||
i += LaunchServer.server.cacheHandler.stageArea[e].isInit() ? 1 : 0;
|
|
||||||
}
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stretchCache(Client client, ChannelHandlerContext ctx){
|
public OAuthManager(){
|
||||||
getUnused().setEntry(client, ctx);
|
stageArea = new Entry[]{
|
||||||
|
new Entry(), new Entry(), new Entry(), new Entry(), new Entry()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entry getUnused(){
|
public static void stretchCache(ChannelHandlerContext ctx, Client client){
|
||||||
for(int i=0; i < 5; i++ )
|
|
||||||
{
|
|
||||||
if(!LaunchServer.server.cacheHandler.stageArea[i].isInit())
|
|
||||||
return LaunchServer.server.cacheHandler.stageArea[i];
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
throw new OAuthException("OAuth Overloaded");
|
Entry e = getUnused();
|
||||||
|
e.setter(ctx, client);
|
||||||
|
LogHelper.subDebug("New Entry IP: " + e.getIP());
|
||||||
} catch (OAuthException e) {
|
} catch (OAuthException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entry getEntry(String IP){
|
public static void stretchCache(String IP, AuthRequestEvent authRequestEvent){
|
||||||
for(int i = 0; i < 5; i++ )
|
for(Entry e: LaunchServer.server.cacheHandler.stageArea)
|
||||||
{
|
{
|
||||||
if(LaunchServer.server.cacheHandler.stageArea[i].isInit())
|
if(e.getIP().equals(IP))
|
||||||
if(LaunchServer.server.cacheHandler.stageArea[i].IP().equals(IP))
|
e.setter(authRequestEvent);
|
||||||
return LaunchServer.server.cacheHandler.stageArea[i];
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
throw new OAuthException("Not found in cache");
|
throw new OAuthException("Not found");
|
||||||
}catch (OAuthException e) {
|
} catch (OAuthException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void stretchCache(ChannelHandlerContext ctx, AuthRequestEvent authRequestEvent){
|
||||||
|
for(Entry e: LaunchServer.server.cacheHandler.stageArea)
|
||||||
|
{
|
||||||
|
if(e.getIP().equals(IOHelper.getIP(ctx.channel().remoteAddress())))
|
||||||
|
e.setter(authRequestEvent);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
throw new OAuthException("Not found");
|
||||||
|
} catch (OAuthException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entry[] newEntryArray(){
|
public static Entry getUnused() throws OAuthException {
|
||||||
return new Entry[]{new Entry(), new Entry(), new Entry(), new Entry(), new Entry()};
|
for(Entry e: LaunchServer.server.cacheHandler.stageArea)
|
||||||
|
{
|
||||||
|
if(e.isInit())
|
||||||
|
continue;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new OAuthException("OAuth Overloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class OAuthException extends IOException {
|
public static final class OAuthException extends IOException {
|
||||||
|
@ -159,6 +162,4 @@ public String toString() {
|
||||||
return getMessage();
|
return getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,8 +161,7 @@ public void registerClient(Channel channel) {
|
||||||
|
|
||||||
public void registerResponses() {
|
public void registerResponses() {
|
||||||
registerResponse("auth", AuthResponse.class);
|
registerResponse("auth", AuthResponse.class);
|
||||||
registerResponse("oauth", OAuthResponse.class);
|
registerResponse("OAuthURL", OAuthResponse.class);
|
||||||
registerResponse("OAuthURL", OAuthConfirmResponse.class);
|
|
||||||
registerResponse("checkServer", CheckServerResponse.class);
|
registerResponse("checkServer", CheckServerResponse.class);
|
||||||
registerResponse("joinServer", JoinServerResponse.class);
|
registerResponse("joinServer", JoinServerResponse.class);
|
||||||
registerResponse("profiles", ProfilesResponse.class);
|
registerResponse("profiles", ProfilesResponse.class);
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
package ru.gravit.launchserver.websocket.json.auth;
|
|
||||||
|
|
||||||
import com.vk.api.sdk.client.TransportClient;
|
|
||||||
import com.vk.api.sdk.client.VkApiClient;
|
|
||||||
import com.vk.api.sdk.exceptions.ApiException;
|
|
||||||
import com.vk.api.sdk.exceptions.ClientException;
|
|
||||||
import com.vk.api.sdk.httpclient.HttpTransportClient;
|
|
||||||
import com.vk.api.sdk.objects.UserAuthResponse;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
|
|
||||||
import ru.gravit.launcher.events.request.OAuthConfirmRequestEvent;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
|
||||||
|
|
||||||
import ru.gravit.launchserver.command.handler.OAuthTokenGet;
|
|
||||||
import ru.gravit.launchserver.manangers.OAuthManager;
|
|
||||||
import ru.gravit.launchserver.socket.Client;
|
|
||||||
import ru.gravit.launchserver.websocket.json.SimpleResponse;
|
|
||||||
import ru.gravit.utils.HookException;
|
|
||||||
|
|
||||||
|
|
||||||
public class OAuthConfirmResponse extends SimpleResponse {
|
|
||||||
|
|
||||||
TransportClient transportClient = new HttpTransportClient();
|
|
||||||
VkApiClient vk = new VkApiClient(transportClient);
|
|
||||||
|
|
||||||
public String code;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(ChannelHandlerContext ctx, Client clientData) throws Exception {
|
|
||||||
try {
|
|
||||||
if(code == null) {
|
|
||||||
try {
|
|
||||||
throw new OAuthManager.OAuthException("Empty code");
|
|
||||||
}catch (OAuthManager.OAuthException e) {
|
|
||||||
sendError(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//LogHelper.debug("code get");
|
|
||||||
|
|
||||||
OAuthTokenGet.mToken(code, vk);
|
|
||||||
int ID = authResponse.getUserId();
|
|
||||||
|
|
||||||
OAuthConfirmRequestEvent result = new OAuthConfirmRequestEvent();
|
|
||||||
result.str = "Continue in Launcher";
|
|
||||||
sendResultAndClose(result);
|
|
||||||
|
|
||||||
} catch (HookException e) {
|
|
||||||
sendError(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType() {
|
|
||||||
return "OAuthURL";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,42 +1,83 @@
|
||||||
package ru.gravit.launchserver.websocket.json.auth;
|
package ru.gravit.launchserver.websocket.json.auth;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.vk.api.sdk.client.TransportClient;
|
||||||
|
import com.vk.api.sdk.client.VkApiClient;
|
||||||
|
import com.vk.api.sdk.client.actors.UserActor;
|
||||||
|
import com.vk.api.sdk.httpclient.HttpTransportClient;
|
||||||
|
import com.vk.api.sdk.objects.UserAuthResponse;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import ru.gravit.launcher.OshiHWID;
|
|
||||||
import ru.gravit.launcher.events.request.OAuthRequestEvent;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
|
import ru.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
|
import ru.gravit.launcher.events.request.LogEvent;
|
||||||
|
|
||||||
|
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||||
|
import ru.gravit.launcher.request.ResultInterface;
|
||||||
|
import ru.gravit.launcher.serialize.HInput;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.launchserver.auth.AuthProviderPair;
|
||||||
|
import ru.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import ru.gravit.launchserver.command.handler.OAuthTokenGet;
|
||||||
import ru.gravit.launchserver.manangers.OAuthManager;
|
import ru.gravit.launchserver.manangers.OAuthManager;
|
||||||
import ru.gravit.launchserver.socket.Client;
|
import ru.gravit.launchserver.socket.Client;
|
||||||
import ru.gravit.launchserver.websocket.json.SimpleResponse;
|
import ru.gravit.launchserver.websocket.json.SimpleResponse;
|
||||||
import ru.gravit.utils.HookException;
|
import ru.gravit.launchserver.websocket.json.profile.ProfileByUUIDResponse;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.util.UUID;
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class OAuthResponse extends SimpleResponse {
|
public class OAuthResponse extends SimpleResponse {
|
||||||
|
|
||||||
public OshiHWID hwid;
|
TransportClient transportClient = new HttpTransportClient();
|
||||||
|
VkApiClient vk = new VkApiClient(transportClient);
|
||||||
|
|
||||||
|
|
||||||
|
public String code;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(ChannelHandlerContext ctx, Client clientData) throws Exception {
|
public void execute(ChannelHandlerContext ctx, Client clientData) {
|
||||||
try {
|
try {
|
||||||
OAuthManager.stretchCache(clientData, ctx);
|
if(code == null) {
|
||||||
OAuthRequestEvent result = new OAuthRequestEvent();
|
try {
|
||||||
result.URL = getAcsessURL();
|
throw new OAuthManager.OAuthException("Empty code");
|
||||||
sendResult(result);
|
}catch (OAuthManager.OAuthException e) {
|
||||||
} catch (HookException e) {
|
|
||||||
sendError(e.getMessage());
|
sendError(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public URL getAcsessURL() throws MalformedURLException {
|
|
||||||
|
|
||||||
String url = "http://oauth.vk.com/authorize?client_id=" + LaunchServer.server.config.OAuthAppID + "&display=page&scope=offline&response_type=code&v=5.69&redirect_uri=" + LaunchServer.server.config.getOAuthBackURL();
|
UserAuthResponse authResponse = OAuthTokenGet.mToken(code, vk);
|
||||||
return new URL(url);
|
|
||||||
|
UserActor actor = new UserActor(authResponse.getUserId(), authResponse.getAccessToken());
|
||||||
|
sendResultAndClose(new LogEvent("Continue in Launcher"));
|
||||||
|
AuthProviderResult ar;
|
||||||
|
AuthProviderPair ap;
|
||||||
|
if(LaunchServer.server.config.getAuthProviderPair("MySQLAuthProvider") != null) {
|
||||||
|
ar = LaunchServer.server.config.getAuthProviderPair("MySQLAuthProvider").provider.oauth(actor.getId());
|
||||||
|
ap = LaunchServer.server.config.getAuthProviderPair("MySQLAuthProvider");
|
||||||
|
}else {
|
||||||
|
ar = LaunchServer.server.config.getAuthProviderPair().provider.oauth(actor.getId());
|
||||||
|
ap = LaunchServer.server.config.getAuthProviderPair();
|
||||||
}
|
}
|
||||||
|
LogHelper.subDebug("found account " + ar.username);
|
||||||
|
|
||||||
|
UUID uuid = ap.handler.auth(ar);
|
||||||
|
PlayerProfile playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, ar.username, "client", clientData.auth.textureProvider);
|
||||||
|
AuthRequestEvent a = new AuthRequestEvent(playerProfile, ar.accessToken, ar.permissions);
|
||||||
|
OAuthManager.stretchCache(ctx, a);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
sendError(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return "oauth";
|
return "OAuthURL";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@ var config = {
|
||||||
// Menu config
|
// Menu config
|
||||||
discord: new java.net.URL("https://discord.gg/aJK6nMN"),
|
discord: new java.net.URL("https://discord.gg/aJK6nMN"),
|
||||||
|
|
||||||
|
OAuthAppID: 0,
|
||||||
|
OAuthBackURL: "https://%address%/OAuth.html",
|
||||||
|
|
||||||
// Settings defaults
|
// Settings defaults
|
||||||
settingsMagic: 0xC0DE5, // Magic, don't touch
|
settingsMagic: 0xC0DE5, // Magic, don't touch
|
||||||
autoEnterDefault: false, // Should autoEnter be enabled by default?
|
autoEnterDefault: false, // Should autoEnter be enabled by default?
|
||||||
|
|
|
@ -307,15 +307,23 @@ function doAuth(login, rsaPassword, auth_type) {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function doOAuth() {
|
function doOAuth() {
|
||||||
processing.resetOverlay();
|
processing.resetOverlay();
|
||||||
overlay.show(processing.overlay, function (event) {
|
overlay.show(processing.overlay, function (event) {
|
||||||
FunctionalBridge.getHWID.join();
|
FunctionalBridge.getHWID.join();
|
||||||
makeOAuthRequest(function (result) {
|
openURL(getOAuthURL());
|
||||||
openURL(new java.net.URL(result.URL));
|
overlay.hide(300000, function () {
|
||||||
overlay.hide(600000, function () {
|
|
||||||
setCurrentScene(loginScene);
|
setCurrentScene(loginScene);
|
||||||
});
|
});
|
||||||
|
makeOAuthRequest(function (result) {
|
||||||
|
FunctionalBridge.setAuthParams(result);
|
||||||
|
loginData = { pp: result.playerProfile , accessToken: result.accessToken, permissions: result.permissions,
|
||||||
|
auth_type: "OAuth"};
|
||||||
|
|
||||||
|
overlay.hide(0, function () {
|
||||||
|
setCurrentScene(menuScene);
|
||||||
|
});
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -121,18 +121,18 @@ function makeAuthRequest(login, rsaPassword, auth_type, callback) {
|
||||||
task.updateMessage("Авторизация на сервере");
|
task.updateMessage("Авторизация на сервере");
|
||||||
startTask(task);
|
startTask(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOAuthURL() {
|
||||||
|
return new java.net.URL("http://oauth.vk.com/authorize?client_id="+ config.OAuthAppID +
|
||||||
|
"&display=page&scope=offline&response_type=code&v=5.69&redirect_uri=" + config.OAuthBackURL)
|
||||||
|
}
|
||||||
|
|
||||||
function makeOAuthRequest(callback) {
|
function makeOAuthRequest(callback) {
|
||||||
var task = newRequestTask(new OAuthRequest(FunctionalBridge.getHWID()));
|
var task = newRequestTask(new OAuthRequest(FunctionalBridge.getHWID()));
|
||||||
processing.setTaskProperties(task, callback, null, true);
|
processing.setTaskProperties(task, callback, null, true);
|
||||||
task.updateMessage("Ожидание авторизация на сервере");
|
task.updateMessage("Ожидание авторизация на сервере");
|
||||||
startTask(task);
|
startTask(task);
|
||||||
}
|
}
|
||||||
function makeOAuthRequest(callback) {
|
|
||||||
var task = newRequestTask(new OAuthRequest(FunctionalBridge.getHWID()));
|
|
||||||
processing.setTaskProperties(task, callback, null, true);
|
|
||||||
startTask(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function launchClient(assetHDir, clientHDir, profile, params, callback) {
|
function launchClient(assetHDir, clientHDir, profile, params, callback) {
|
||||||
var task = newTask(function() ClientLauncher.launch(assetHDir, clientHDir,
|
var task = newTask(function() ClientLauncher.launch(assetHDir, clientHDir,
|
||||||
|
|
Loading…
Reference in a new issue