Ejemplo n.º 1
0
        public void TestGetDevice()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevInfo);

                AccessSdk sdk = new AccessSdk(accessUrl, merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                DeviceInfo dInfo = sdk.GetDevice(session);

                Assert.IsNotNull(dInfo);
                this.logger.Debug(JsonConvert.SerializeObject(dInfo));

                Assert.AreEqual(fingerprint, dInfo.Device.Id);
                Assert.AreEqual(ipAddress, dInfo.Device.IpAddress);
                Assert.AreEqual(ipGeo, dInfo.Device.IpGeo);
                Assert.AreEqual(1, dInfo.Device.Mobile);
                Assert.AreEqual(0, dInfo.Device.Proxy);
                Assert.AreEqual(responseId, dInfo.ResponseId);
            }
            catch (AccessException ae)
            {
                Assert.Fail($"Bad exception {ae.ErrorType}:{ae.Message}");
            }
        }
Ejemplo n.º 2
0
        public void TestGetDeviceConnectionClosed()
        {
            try
            {
                MockupWebClientFactory mockFactory = new MockupWebClientFactory(this.jsonDevInfo);

                AccessSdk sdk = new AccessSdk("gty://bad.host.com", merchantId, apiKey, DEFAULT_VERSION, mockFactory);

                DeviceInfo dInfo = sdk.GetDevice(session);

                Assert.Fail($"AccessException Not thrown");
            }
            catch (AccessException ae)
            {
                Assert.AreEqual(ae.ErrorType, AccessErrorType.NETWORK_ERROR);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Simple Example within the Constructor.
        /// </summary>
        public KountAccessExample()
        {
            try
            {
                // Create the SDK. If any of these values are invalid, an com.kount.kountaccess.AccessException will be
                // thrown along with a message detailing why.
                AccessSdk sdk = new AccessSdk(host, merchantId, apiKey);

                // If you want the device information for a particular user's session, just pass in the sessionId. This
                // contains the id (fingerprint), IP address, IP Geo Location (country), whether the user was using a proxy
                // (and it was bypassed), and ...
                DeviceInfo deviceInfo = sdk.GetDevice(this.session);

                this.PrintDeviceInfo(deviceInfo.Device);

                // ... if you want to see the velocity information in relation to the users session and their account
                // information, you can make an access (velocity) request. Usernames and passwords will be hashed prior to
                // transmission to Kount within the SDK. You may optionally hash prior to passing them in as long as the
                // hashing method is consistent for the same value.
                String       username   = "******";
                String       password   = "******";
                VelocityInfo accessInfo = sdk.GetVelocity(session, username, password);

                // Let's see the response
                Console.WriteLine("Response: " + accessInfo);

                // Each Access Request has its own uniqueID
                Console.WriteLine("This is our access response_id: " + accessInfo.ResponseId);

                // The device is included in an access request:
                this.PrintDeviceInfo(accessInfo.Device);

                // you can get the device information from the accessInfo object
                Device device = accessInfo.Device;

                string jsonVeloInfo = JsonConvert.SerializeObject(accessInfo);
                Console.WriteLine(jsonVeloInfo);

                this.PrintVelocityInfo(accessInfo.Velocity);

                // Or you can access specific Metrics directly. Let's say we want the
                // number of unique user accounts used by the current sessions device
                // within the last hour
                int numUsersForDevice = accessInfo.Velocity.Device.ulh;
                Console.WriteLine(
                    "The number of unique user access request(s) this hour for this device is:" + numUsersForDevice);

                // Decision Information is stored in a JSONObject, by entity type
                DecisionInfo decisionInfo = sdk.GetDecision(session, username, password);
                Decision     decision     = decisionInfo.Decision;
                // Let's look at the data
                this.PrintDecisionInfo(decision);

                // Get Kount Access data for session based on what was requested in the info flag
                String          uniq    = "uniq(customer identifier)";
                DataSetElements dataSet = new DataSetElements()
                                          .WithInfo()
                                          .WithVelocity()
                                          .WithDecision()
                                          .WithTrusted()
                                          .WithBehavioSec();

                Info info = sdk.GetInfo(session, username, password, uniq, dataSet);
                this.PrintDeviceInfo(info.Device);
                this.PrintDecisionInfo(info.Decision);
                this.PrintVelocityInfo(info.Velocity);
                this.PrintFields(info.Trusted);
                this.PrintFields(info.BehavioSec);

                // Get devices that belong to a uniq user.
                DevicesInfo devices = sdk.GetDevices(uniq);
                foreach (var d in devices.Devices)
                {
                    this.PrintFields(d);
                }

                // Get the uniq users that belong to a device.
                string deviceId = "DEVICE_ID";
                var    uniques  = sdk.GetUniques(deviceId);
                foreach (var u in uniques.Uniques)
                {
                    this.PrintFields(u);
                }

                // Update device trust referenced by session ID
                sdk.SetDeviceTrustBySession(session, uniq, DeviceTrustState.Banned);

                // Update device trust referenced by device ID
                sdk.SetDeviceTrustByDevice(uniq, deviceId, DeviceTrustState.Trusted);

                // Update behavior data.
                string timing = "timing data";
                // BehavioHost and BehavioEnvironment can be set via AccessSdk constructor too.
                // sdk.BehavioHost = "https://api.behavio.kaptcha.com";
                //sdk.BehavioEnvironment = "sandbox";

                //sdk.SetBehavioSec(session, uniq, timing);
            }
            catch (AccessException ae)
            {
                // These can be thrown if there were any issues making the request.
                // See the AccessException class for more information.
                Console.WriteLine("ERROR Type: " + ae.ErrorType);
                Console.WriteLine("ERROR: " + ae.Message);
            }
        }