Пример #1
0
        public void ShouldSerializeCorrectly_WithPushTitle()
        {
            var encoder = new JsonNetJsonEncoder();
            var o       = new ServiceV3AuthsPostRequest("my-unique-user-identifier", null, null, null, null, "Push Title", null, null);
            var json    = encoder.EncodeObject(o);

            Assert.AreEqual("{\"username\":\"my-unique-user-identifier\",\"push_title\":\"Push Title\"}", json);
        }
Пример #2
0
        public void ShouldSerializeCorrectly_WithContext()
        {
            var encoder = new JsonNetJsonEncoder();
            var o       = new ServiceV3AuthsPostRequest("my-unique-user-identifier", null, "Authorizing charge for $12.34 at iovation.com", null, null, null, null, null);
            var json    = encoder.EncodeObject(o);

            Assert.AreEqual("{\"username\":\"my-unique-user-identifier\",\"context\":\"Authorizing charge for $12.34 at iovation.com\"}", json);
        }
Пример #3
0
        public void ShouldSerializeCorrectly_WithDenialReasons()
        {
            var encoder       = new JsonNetJsonEncoder();
            var denialReasons = new List <DenialReason> {
                new DenialReason("1", "Reason 1", true), new DenialReason("2", "Reason 2", false)
            };
            var o    = new ServiceV3AuthsPostRequest("my-unique-user-identifier", null, null, null, null, null, null, denialReasons);
            var json = encoder.EncodeObject(o);

            Assert.AreEqual("{\"username\":\"my-unique-user-identifier\",\"denial_reasons\":[{\"id\":\"1\",\"reason\":\"Reason 1\",\"fraud\":true},{\"id\":\"2\",\"reason\":\"Reason 2\",\"fraud\":false}]}", json);
        }
Пример #4
0
        public ServiceV3AuthsPostResponse ServiceV3AuthsPost(ServiceV3AuthsPostRequest request, EntityIdentifier subject)
        {
            var response = ExecuteRequest(
                HttpMethod.POST,
                "/service/v3/auths",
                subject,
                request,
                null
                );

            return(DecryptResponse <ServiceV3AuthsPostResponse>(response));
        }
Пример #5
0
        public void Constructor_ShouldSetProperties()
        {
            var authPolicy = new AuthPolicy(null, null, null, null, null, null);
            var o          = new ServiceV3AuthsPostRequest("un", authPolicy, "ctx", "title", 999, "Push Title", "Push Body", new List <DenialReason> {
                new DenialReason("1", "a", true)
            });

            Assert.AreSame(o.AuthPolicy, authPolicy);
            Assert.AreEqual(o.Context, "ctx");
            Assert.AreEqual(o.Username, "un");
            Assert.AreEqual(o.Title, "title");
            Assert.AreEqual(o.TTL, 999);
            Assert.AreEqual(o.PushTitle, "Push Title");
            Assert.AreEqual(o.PushBody, "Push Body");
            Assert.AreEqual(o.DenialReasons[0], new DenialReason("1", "a", true));
        }
Пример #6
0
        public void ShouldSerializeCorrectly_WithPolicy()
        {
            var encoder = new JsonNetJsonEncoder();
            var policy  = new AuthPolicy(2, null, null, null, null,
                                         new System.Collections.Generic.List <AuthPolicy.Location>
            {
                new AuthPolicy.Location
                {
                    Radius    = 60,
                    Latitude  = 27.175,
                    Longitude = 78.0422
                }
            }
                                         );
            var o        = new ServiceV3AuthsPostRequest("my-unique-user-identifier", policy, null, null, null, null, null, null);
            var json     = encoder.EncodeObject(o);
            var expected = "{\"username\":\"my-unique-user-identifier\",\"policy\":{\"minimum_requirements\":[{\"requirement\":\"authenticated\",\"any\":2}],\"factors\":[{\"factor\":\"geofence\",\"requirement\":\"forced requirement\",\"priority\":1,\"attributes\":{\"locations\":[{\"radius\":60.0,\"latitude\":27.175,\"longitude\":78.0422}]}}]}}";

            Assert.AreEqual(expected, json);
        }
Пример #7
0
        public AuthorizationRequest CreateAuthorizationRequest(string user, string context = null, AuthPolicy policy = null, string title = null, int?ttl = null, string pushTitle = null, string pushBody = null, IList <DenialReason> denialReasons = null)
        {
            Transport.Domain.AuthPolicy requestPolicy = null;
            if (policy != null)
            {
                requestPolicy = new Transport.Domain.AuthPolicy(
                    policy.RequiredFactors,
                    policy.RequireKnowledgeFactor,
                    policy.RequireInherenceFactor,
                    policy.RequirePosessionFactor,
                    policy.JailbreakDetection,
                    policy.Locations?.Select(
                        ploc => new Transport.Domain.AuthPolicy.Location
                {
                    Latitude  = ploc.Latitude,
                    Longitude = ploc.Longitude,
                    Radius    = ploc.Radius
                }
                        ).ToList()
                    );
            }
            List <TransportDenialReason> transportDenialReasons;

            if (denialReasons == null)
            {
                transportDenialReasons = null;
            }
            else
            {
                transportDenialReasons = new List <TransportDenialReason>();
                foreach (DenialReason dr in denialReasons)
                {
                    transportDenialReasons.Add(new TransportDenialReason(dr.Id, dr.Reason, dr.Fraud));
                }
            }
            var request     = new ServiceV3AuthsPostRequest(user, requestPolicy, context, title, ttl, pushTitle, pushBody, transportDenialReasons);
            var response    = _transport.ServiceV3AuthsPost(request, _serviceId);
            var authRequest = new AuthorizationRequest(response.AuthRequest.ToString("D"), response.PushPackage, response.DeviceIDs);

            return(authRequest);
        }