SocketIOServer server = new SocketIOServer(config);
AuthTokenListener listener = (authData, client) -> authToken(authData, client, tokenService);
server.getNamespace("").addAuthTokenListener(listener);
/**
* authToken
*/
private AuthTokenResult authToken(Object authData, SocketIOClient client, TokenService tokenService) {
LoginUser loginUser = tokenService.getByToken(resolveToken(authData));
if (loginUser == null) return fail("Invalid token");
client.getHandshakeData().setAuthToken(loginUser);
return AuthTokenResult.AuthTokenResultSuccess;
}
The authToken function no run while a client connecting without token.
The authToken function no run while a client connecting without token.