private void ReceiveAuthenticationRequestCallback(PyDataType packet) { AuthenticationReq request = packet; if (request.user_password is null) { Log.Trace("Rejected by server; requesting plain password"); // request the user a plain password this.Socket.Send(new PyInteger(1)); // 1 => plain, 2 => hashed return; } // TODO: DINAMICALLY FETCH THIS SO WE SUPPORT TRANSLATIONS if (request.user_languageid != "EN" && request.user_languageid != "RU" && request.user_languageid != "DE") { // default to english language this.Session["languageID"] = "EN"; } else { // set languageid in the session to the one requested as we have translations for that one this.Session["languageID"] = request.user_languageid; } // add the user to the authentication queue this.ConnectionManager.LoginQueue.Enqueue(this, request); }
public async Task <IActionResult> Post([FromBody] AuthenticationReq requestModel) { var result = await _communicator .AuthenticateAsync(requestModel, CancellationToken.None).ConfigureAwait(false); return(Ok(result)); }
public async Task <AuthenticationResp> AuthenticateAsync (AuthenticationReq request, CancellationToken cancellationToken = default) { using var socket = new ClientWebSocket(); await socket.ConnectAsync(_webSocketUri, cancellationToken).ConfigureAwait(false); return(await WebSocketRequest <AuthenticationReq, AuthenticationResp>(request, socket).ConfigureAwait(false)); }
private Task <AuthenticationResp> AuthenticateAsync (WebSocket socket, CancellationToken cancellationToken = default) { var request = new AuthenticationReq() { Login = login, Password = password, }; return(WebSocketRequest <AuthenticationReq, AuthenticationResp>(request, socket, 2048, cancellationToken)); }
public void Enqueue(ClientConnection connection, AuthenticationReq request) { // Just to be thread safe lock (this.Queue) { LoginQueueEntry entry = new LoginQueueEntry(); entry.Connection = connection; entry.Request = request; this.Queue.Enqueue(entry); } }
public static void Enqueue(Connection con, AuthenticationReq packet) { // Just to be thread safe lock (queue) { LoginQueueEntry entry = new LoginQueueEntry(); entry.connection = con; entry.request = packet; queue.Enqueue(entry); } }
/// <summary> /// Gets the user details from service. /// </summary> /// <returns>The user details from service.</returns> /// <param name="userName">User name.</param> /// <param name="password">Password.</param> public Model.AuthenticatedUser GetUserDetailsFromService(String userName, String password) { IServices servicesObject = new Services(); AuthenticationReq request = new AuthenticationReq(); request.userName = userName; request.password = password; AuthenticationRes authenticationResult = null; Model.AuthenticatedUser authenticatedUser = new Model.AuthenticatedUser (); try { UserService userServiceObject = new UserService (conn); authenticationResult = servicesObject.authenticate (request); bool isTokenActive = this.CheckIfTokenIsActive(authenticationResult.expiryTime); authenticatedUser.IsFirstTimeLoggedIn = true; if (authenticationResult.result != null) authenticatedUser.Result = authenticationResult.result; if (!string.IsNullOrEmpty (authenticationResult.token)) { authenticatedUser.UserDetails = new Model.User (); authenticatedUser.UserDetails.Token = authenticationResult.token; authenticatedUser.UserDetails.FirstName = authenticationResult.firstName; authenticatedUser.UserDetails.LastName = authenticationResult.lastName; authenticatedUser.UserDetails.ExpiryDate = authenticationResult.expiryTime; authenticatedUser.IsTokenActive = isTokenActive; authenticatedUser.DBVersion=authenticationResult.DBVersion; //Delete the previous exist users userServiceObject.DeleteUser(conn); //save the details of the user in the database userServiceObject.SaveUser (authenticatedUser.UserDetails); try { var user=userServiceObject.GetUsers ().FirstOrDefault (); if (user != null && authenticatedUser!=null) { authenticatedUser.UserDetails.ID = user.ID; } } catch(Exception ex) { // To DO } } } catch(Exception ex) { } return authenticatedUser; }
public AuthenticationRes authenticate(AuthenticationReq req) { return(new AuthenticationRes() { firstName = "Robert", lastName = "Heslar", token = "uiwe90221921-daksds", expiryTime = DateTime.Now.AddHours(10), result = new Model.ServiceModel.Result() { code = 0, message = "OK" }, DBVersion = "1.0" }); }
private void ReceiveAuthenticationRequestCallback(PyDataType packet) { AuthenticationReq request = packet; if (request.user_password == null) { Log.Trace("Rejected by server; requesting plain password"); // request the user a plain password this.Socket.Send(new PyInteger(1)); // 1 => plain, 2 => hashed return; } // set languageid in the session this.Session["languageID"] = request.user_languageid; // add the user to the authentication queue this.ConnectionManager.LoginQueue.Enqueue(this, request); }
public VegaRequestBuilder AddAuthentication(string user, string password, Action <AuthenticationResp>?action) { const int responceBufferSice = 10000; var authenticationReuest = new AuthenticationReq() { Login = user, Password = password }; Func <WebSocket, CancellationToken, Task> newAction = async(socket, token) => { var result = await WebSocketRequest <AuthenticationReq, AuthenticationResp> (authenticationReuest, socket, responceBufferSice, token).ConfigureAwait(false); action?.Invoke(result); }; actions.Add(newAction); return(this); }
private static PyObject HandleTuple(PyTuple tup, Connection connection) { int items = tup.Items.Count; if (items == 6) { // Only LowLeverVersionExchange if (connection.CheckLowLevelVersionExchange(tup) == false) { connection.EndConnection(); } if (connection.Type == ConnectionType.Node) { // Update the list in ConnectionManager ConnectionManager.UpdateConnection(connection); // Send the node info connection.SendNodeChangeNotification(); // Flag the connection as fully handled to start the correct listener connection.StageEnded = true; } else if (connection.Type == ConnectionType.Client) { // Update the list in ConnectionManager(we should do this later) // ConnectionManager.UpdateConnection(connection); } return(null); } else if (items == 3) { if (tup.Items[0].Type == PyObjectType.None) { // VipKey VipKeyCommand vk = new VipKeyCommand(); if (vk.Decode(tup) == false) { Log.Error("Client", "Wrong vipKey command"); connection.EndConnection(); return(null); } return(null); } else { // Handshake sent when we are mostly in HandshakeAck ack = new HandshakeAck(); ack.live_updates = new PyList(); ack.jit = connection.LanguageID; ack.userid = (int)connection.AccountID; ack.maxSessionTime = new PyNone(); ack.userType = Common.Constants.AccountType.User; ack.role = (int)connection.Role; ack.address = connection.Address; ack.inDetention = new PyNone(); ack.client_hashes = new PyList(); ack.user_clientid = (int)connection.AccountID; // We have to send this just before the sessionchange connection.Send(ack.Encode()); // Send session change connection.SendSessionChange(); // Change the stage to ended to start the real listener connection.StageEnded = true; } } else if (items == 2) // PlaceboRequest, QueueCheck and Login packet { if (tup.Items[0].Type == PyObjectType.None) { QueueCheckCommand qc = new QueueCheckCommand(); if (qc.Decode(tup) == false) { Log.Error("Client", "Wrong QueueCheck command"); connection.EndConnection(); return(null); } // Queued logins connection.Send(new PyInt(LoginQueue.queue.Count + 1)); connection.SendLowLevelVersionExchange(); return(null); } else if (tup.Items[0].Type == PyObjectType.String) { if (tup.Items[0].As <PyString>().Value == "placebo") { // We assume it is a placebo request PlaceboRequest req = new PlaceboRequest(); if (req.Decode(tup) == false) { Log.Error("Client", "Wrong placebo request"); connection.EndConnection(); return(null); } return(new PyString("OK CC")); } else { // Check if the password is hashed or not and ask for plain password AuthenticationReq req = new AuthenticationReq(); // Send AutClusterStarting message if we do not have any node attached yet if (ConnectionManager.NodesCount <= 0) { GPSTransportClosed ex = new GPSTransportClosed("AutClusterStarting"); connection.Send(ex.Encode()); connection.EndConnection(); return(null); } if (req.Decode(tup) == false) { Log.Error("Client", "Wrong login packet"); GPSTransportClosed ex = new GPSTransportClosed("LoginAuthFailed"); connection.Send(ex.Encode()); connection.EndConnection(); return(null); } Log.Debug("Client", "Login try: " + req.user_name); // The hash is in sha1, we should handle it later if (req.user_password == null) { Log.Trace("Client", "Rejected by server; requesting plain password"); return(new PyInt(1)); // Ask for unhashed password( 1 -> Plain, 2 -> Hashed ) } // Login request, add it to the queue and wait until we are accepted or rejected LoginQueue.Enqueue(connection, req); // The login queue will call send the data to the client return(null); } } } else { Log.Error("Connection", "Unhandled Tuple packet with " + items + " items"); connection.EndConnection(); return(null); } return(null); }
private PyObject HandleTuple(PyTuple tup) { int items = tup.Items.Count; if (items == 6) { // Only LowLeverVersionExchange if (CheckLowLevelVersionExchange(tup) == false) { Close(); } if (isNode) { // We are a node, the next packets will be handled by the Node class Node n = new Node(new StreamPacketizer(), socket); NodeManager.AddNode(n); forClose = false; Close(); } return(null); } else if (items == 3) { if (tup.Items[0].Type == PyObjectType.None) { // VipKey VipKeyCommand vk = new VipKeyCommand(); if (vk.Decode(tup) == false) { Log.Error("Client", "Wrong vipKey command"); Close(); return(null); } return(null); } else { // Handshake sent when we are mostly in HandshakeAck ack = new HandshakeAck(); ack.live_updates = new PyList(); ack.jit = session.GetCurrentString("languageID"); ack.userid = session.GetCurrentInt("userid"); ack.maxSessionTime = new PyNone(); ack.userType = Common.Constants.AccountType.User; ack.role = session.GetCurrentInt("role"); ack.address = session.GetCurrentString("address"); ack.inDetention = new PyNone(); ack.client_hashes = new PyList(); ack.user_clientid = session.GetCurrentInt("userid"); // We have to send this just before the sessionchange Send(ack.Encode()); // Create the client instance Client cli = new Client(new StreamPacketizer(), socket); // Update the Client class session data cli.InitialSession(session); // Set the node id for the client cli.SetNodeID(nodeID); // Send session change cli.SendSessionChange(); // Start the client packet reader thread cli.Start(); // Now we are completely in, add us to the list ClientManager.AddClient(cli); // Delete ourselves from the list forClose = false; Close(); } } else if (items == 2) // PlaceboRequest, QueueCheck and Login packet { if (tup.Items[0].Type == PyObjectType.None) { QueueCheckCommand qc = new QueueCheckCommand(); if (qc.Decode(tup) == false) { Log.Error("Client", "Wrong QueueCheck command"); Close(); return(null); } // Queued logins Send(new PyInt(LoginQueue.queue.Count + 1)); SendLowLevelVersionExchange(); return(null); } else if (tup.Items[0].Type == PyObjectType.String) { if (tup.Items[0].As <PyString>().Value == "placebo") { // We assume it is a placebo request PlaceboRequest req = new PlaceboRequest(); if (req.Decode(tup) == false) { Log.Error("Client", "Wrong placebo request"); Close(); return(null); } return(new PyString("OK CC")); } else { // Check if the password is hashed or not and ask for plain password AuthenticationReq req = new AuthenticationReq(); if (req.Decode(tup) == false) { Log.Error("Client", "Wrong login packet"); GPSTransportClosed ex = new GPSTransportClosed("LoginAuthFailed"); Send(ex.Encode()); Close(); return(null); } // The hash is in sha1, we should handle it later if (req.user_password == null) { Log.Trace("Client", "Rejected by server; requesting plain password"); return(new PyInt(1)); // Ask for unhashed password( 1 -> Plain, 2 -> Hashed ) } request = req; // Login request, add it to the queue and wait until we are accepted or rejected LoginQueue.Enqueue(this); // The login queue will call send the data to the client return(null); } } } else { Log.Error("Connection", "Unhandled Tuple packet with " + items + " items"); thr.Abort(); return(null); } return(null); }
public AuthenticationRes authenticate(AuthenticationReq req) { Uri uri = new Uri(ServiceURL.UrlAuth); return(request <AuthenticationReq, AuthenticationRes> .executePost(req, uri)); }