[FEATURE] Поддержка 2FA и необычных способах авторизации

This commit is contained in:
Gravit 2019-11-30 02:41:27 +07:00
parent ede1749f58
commit e081bf5a76
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 33 additions and 2 deletions

View file

@ -1,5 +1,6 @@
package pro.gravit.launchserver.auth.provider; package pro.gravit.launchserver.auth.provider;
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
import pro.gravit.launcher.request.auth.AuthRequest; import pro.gravit.launcher.request.auth.AuthRequest;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthException;
@ -12,6 +13,13 @@ public abstract class AuthProvider implements AutoCloseable {
private static boolean registredProv = false; private static boolean registredProv = false;
protected transient LaunchServer srv = null; protected transient LaunchServer srv = null;
public GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType getFirstAuthType() {
return GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType.PASSWORD;
}
public GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType getSecondAuthType() {
return GetAvailabilityAuthRequestEvent.AuthAvailability.AuthType.NONE;
}
public static AuthProviderResult authError(String message) throws AuthException { public static AuthProviderResult authError(String message) throws AuthException {
throw new AuthException(message); throw new AuthException(message);
} }

View file

@ -19,7 +19,7 @@ public String getType() {
public void execute(ChannelHandlerContext ctx, Client client) { public void execute(ChannelHandlerContext ctx, Client client) {
List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>(); List<GetAvailabilityAuthRequestEvent.AuthAvailability> list = new ArrayList<>();
for (AuthProviderPair pair : server.config.auth) { for (AuthProviderPair pair : server.config.auth) {
list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName)); list.add(new GetAvailabilityAuthRequestEvent.AuthAvailability(pair.name, pair.displayName, pair.provider.getFirstAuthType(), pair.provider.getSecondAuthType()));
} }
sendResult(new GetAvailabilityAuthRequestEvent(list)); sendResult(new GetAvailabilityAuthRequestEvent(list));
} }

View file

@ -11,10 +11,33 @@ public static class AuthAvailability {
public final String name; public final String name;
@LauncherNetworkAPI @LauncherNetworkAPI
public final String displayName; public final String displayName;
@LauncherNetworkAPI
public final AuthType firstType;
@LauncherNetworkAPI
public final AuthType secondType;
public AuthAvailability(String name, String displayName) { public AuthAvailability(String name, String displayName, AuthType firstType, AuthType secondType) {
this.name = name; this.name = name;
this.displayName = displayName; this.displayName = displayName;
this.firstType = firstType;
this.secondType = secondType;
}
public enum AuthType
{
@LauncherNetworkAPI
PASSWORD,
@LauncherNetworkAPI
KEY,
@LauncherNetworkAPI
TOTP,
@LauncherNetworkAPI
OAUTH,
@LauncherNetworkAPI
NONE,
@LauncherNetworkAPI
OTHER
} }
} }