Beispiel #1
0
        public static ClientAuthenticationResult ClientLogin(ClientAuthenticationRequest request)
        {
            var result = new ClientAuthenticationResult();

            if (string.IsNullOrEmpty(request.Nick) || string.IsNullOrEmpty(request.Password))
            {
                result.Result = ClientAuthenticationResult.AuthResult.InvalidRequest;
            }
            else if (!AuthenticationController.ValidatePassword(request.Password))
            {
                result.Result = ClientAuthenticationResult.AuthResult.BadPassword;
            }
            else if (_connectedClients.Contains(request.Nick, StringComparer.OrdinalIgnoreCase))
            {
                result.Result = ClientAuthenticationResult.AuthResult.NickInUse;
            }
            else if (AuthenticationController.ValidatePassword(request.Password))
            {
                result.Result = ClientAuthenticationResult.AuthResult.LoginSuccess;
                result.Token  = AuthenticationController.GenerateAuthenticationToken(request.Nick);
                AddNewClient(request.Nick);
            }

            else
            {
                result.Result = ClientAuthenticationResult.AuthResult.UnknownError;
            }

            return(result);
        }
Beispiel #2
0
 public void LoginSuccess()
 {
     var request = new ClientAuthenticationRequest { Nick = "nilminus", Password = "******" };
     var result = Controllers.ClientController.ClientLogin(request);
     Assert.Equal(ClientAuthenticationResult.AuthResult.LoginSuccess, result.Result);
     Assert.NotNull(result.Token);
 }
Beispiel #3
0
        public ClientAuthenticationResult ClientLogin(ClientAuthenticationRequest request)
        {
            var result = new ClientAuthenticationResult();

            if (string.IsNullOrEmpty(request.Nick) || string.IsNullOrEmpty(request.Password))
            {
                result.Result = ClientAuthenticationResult.AuthResult.InvalidRequest;
                Log.Logger.Warning("CLIENT {AuthResult} {Nick}", result.Result.ToString(), request.Nick);
            }
            else if (!AuthenticationController.ValidatePassword(request.Password))
            {
                result.Result = ClientAuthenticationResult.AuthResult.BadPassword;
                Log.Logger.Warning("CLIENT {AuthResult} {Nick}", result.Result.ToString(), request.Nick);
            }
            else if (ConnectedClients.Contains(request.Nick, StringComparer.OrdinalIgnoreCase))
            {
                result.Result = ClientAuthenticationResult.AuthResult.NickInUse;
                Log.Logger.Warning("CLIENT {AuthResult} {Nick}", result.Result.ToString(), request.Nick);
            }
            else
            {
                result.Result = ClientAuthenticationResult.AuthResult.LoginSuccess;
                result.Token  = AuthenticationController.GenerateAuthenticationToken(request.Nick);

                Log.Logger.Information("CLIENT {AuthResult} {Nick}", result.Result.ToString(), request.Nick);

                AddNewClient(request.Nick);
            }

            return(result);
        }
Beispiel #4
0
        public async Task <IActionResult> AuthenticateClient([FromBody] ClientAuthenticationRequest authenticationRequest)
        {
            if (authenticationRequest == null || authenticationRequest.ApiKey == null)
            {
                return(HandleBadRequest("An API key needs to be supplied for client authentication requests."));
            }

            try
            {
                string token = await AuthenticationService.Authenticate(authenticationRequest.ApiKey);

                if (token != null)
                {
                    return(Ok(new AuthenticationResponse(token)));
                }
                else
                {
                    return(Unauthorized());
                }
            }
            catch (EntityNotFoundException)
            {
                return(Unauthorized());
            }
            catch (Exception exception)
            {
                return(HandleUnexpectedException(exception));
            }
        }
Beispiel #5
0
        public void InvalidRequest()
        {
            var request = new ClientAuthenticationRequest {
                Nick = "nilminus", Password = ""
            };
            var result = TeamServer.Controllers.ClientController.ClientLogin(request);

            Assert.Equal(ClientAuthenticationResult.AuthResult.InvalidRequest, result.Result);
            Assert.Null(result.Token);
        }
Beispiel #6
0
        internal static async Task <ClientAuthenticationResult> ClientLogin(string nick, string pass)
        {
            var authRequest = new ClientAuthenticationRequest {
                Nick = nick, Password = pass
            };
            var response = await HttpClient.PostAsync("api/Client", Helpers.Serialise(authRequest));

            var result = Helpers.Deserialise <ClientAuthenticationResult>(response.Content.ReadAsStringAsync());

            if (result.Result == ClientAuthenticationResult.AuthResult.LoginSuccess)
            {
                HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.Token);
            }

            return(result);
        }
Beispiel #7
0
        public void GetConnectedClients()
        {
            var request = new ClientAuthenticationRequest {
                Nick = "nilminus", Password = "******"
            };

            TeamServer.Controllers.ClientController.ClientLogin(request);
            request = new ClientAuthenticationRequest {
                Nick = "stintixis", Password = "******"
            };
            TeamServer.Controllers.ClientController.ClientLogin(request);

            var result = TeamServer.Controllers.ClientController.GetConnectedClients();

            Assert.Equal(new List <string> {
                "nilminus", "stintixis"
            }, result);
        }
Beispiel #8
0
 public ClientAuthenticationResult ClientLogin([FromBody] ClientAuthenticationRequest request)
 {
     return(Program.ServerController.ClientController.ClientLogin(request));
 }