protected virtual AuthenticateUserRequest BuildAuthenticateRequest()
 {
     var request = new AuthenticateUserRequest();
     request.MaxAttempts = this.MaxAttempts;
     request.TimeoutInSeconds = this.TimeoutInSeconds;
     request.Type = this.Type;
     this.Attributes.For(attr => request[attr.Key] = attr.Value);
     return request;
 }
 public static async Task<string> AuthenticateAsync(string username, string password)
 {
     Console.WriteLine("Authenticating user with username {0} and password {1}", username, password);
     var authRequest = new AuthenticateUserRequest();
     authRequest["username"] = username;
     authRequest["password"] = password;
     var authResponse = await authRequest.ExecuteAsync();
     ApiHelper.EnsureValidResponse(authResponse);
     return authResponse.Token;
 }
        public async Task<AuthenticateUserResponse> AuthenticateAsync(AuthenticateUserRequest request)
        {
            byte[] bytes = null;

            bytes = await HttpOperation
                .WithUrl(Urls.For.AuthenticateUser(request.CurrentLocation, request.DebugEnabled, request.Verbosity, request.Fields))
                .WithAppacitiveSession(request.SessionToken)
                .WithEnvironment(request.Environment)
                .WithUserToken(request.UserToken)
                .PostAsyc(request.ToBytes());
            var response = AuthenticateUserResponse.Parse(bytes);
            return response;
        }
        public async Task AuthenticateWithUsernamePasswordTestAsync()
        {

            // Create the user
            var user = await UserHelper.CreateNewUserAsync();
            var authRequest = new AuthenticateUserRequest();
            authRequest["username"] = user.Username;
            authRequest["password"] = user.Password;
            var authResponse = await authRequest.ExecuteAsync();
            ApiHelper.EnsureValidResponse(authResponse);
            Assert.IsTrue(string.IsNullOrWhiteSpace(authResponse.Token) == false, "Auth token is not valid.");
            Assert.IsNotNull(authResponse.User, "Authenticated user is null.");
            Console.WriteLine("Logged in user id: {0}", authResponse.User.Id);
            Console.WriteLine("Session token: {0}", authResponse.Token);
        }