예제 #1
0
        public void ShouldAddThirdPartyAttributeToProfile()
        {
            var thirdPartyAttribute = TestTools.Attributes.CreateProtobufAttributeFromRawAnchor(TestData.TestAttributes.ThirdPartyAssignedAttribute);

            YotiProfile yotiProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute <string>(thirdPartyAttribute);

            YotiAttribute <string> yotiAttribute = yotiProfile.GetAttributeByName <string>("com.thirdparty.id");

            Assert.AreEqual("test-third-party-attribute-0", yotiAttribute.GetValue());

            Assert.AreEqual("THIRD_PARTY", yotiAttribute.GetSources().First().GetValue());
            Assert.AreEqual("orgName", yotiAttribute.GetSources().First().GetSubType());

            Assert.AreEqual("THIRD_PARTY", yotiAttribute.GetVerifiers().First().GetValue());
            Assert.AreEqual("orgName", yotiAttribute.GetVerifiers().First().GetSubType());

            ReadOnlyCollection <YotiAttribute <string> > yotiAttributes = yotiProfile.GetAttributesByName <string>(name: "com.thirdparty.id");
            var yotiAttributeFromCollection = yotiAttributes.Single();

            Assert.AreEqual("test-third-party-attribute-0", yotiAttributeFromCollection.GetValue());

            Assert.AreEqual("THIRD_PARTY", yotiAttributeFromCollection.GetSources().First().GetValue());
            Assert.AreEqual("orgName", yotiAttributeFromCollection.GetSources().First().GetSubType());

            Assert.AreEqual("THIRD_PARTY", yotiAttributeFromCollection.GetVerifiers().First().GetValue());
            Assert.AreEqual("orgName", yotiAttributeFromCollection.GetVerifiers().First().GetSubType());
        }
예제 #2
0
        // GET: Account/Connect?token
        public ActionResult Connect(string token)
        {
            if (token == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            try
            {
                string sdkId = Environment.GetEnvironmentVariable("YOTI_CLIENT_SDK_ID");
                _logger.LogInformation(string.Format("sdkId='{0}'", sdkId));

                string yotiKeyFilePath = Environment.GetEnvironmentVariable("YOTI_KEY_FILE_PATH");
                _logger.LogInformation(
                    string.Format(
                        "yotiKeyFilePath='{0}'",
                        yotiKeyFilePath));

                StreamReader privateKeyStream = System.IO.File.OpenText(yotiKeyFilePath);

                var yotiClient = new YotiClient(sdkId, privateKeyStream);

                ActivityDetails activityDetails = yotiClient.GetActivityDetails(token);

                var profile = activityDetails.Profile;

                ViewBag.RememberMeID = activityDetails.RememberMeId;

                DisplayAttributes displayAttributes = CreateDisplayAttributes(profile.AttributeCollection);

                if (profile.FullName != null)
                {
                    displayAttributes.FullName = profile.FullName.GetValue();
                }

                YotiAttribute <Image> selfie = profile.Selfie;
                if (profile.Selfie != null)
                {
                    displayAttributes.Base64Selfie = selfie.GetValue().GetBase64URI();
                }

                return(View(displayAttributes));
            }
            catch (Exception e)
            {
                _logger.LogError(
                    exception: e,
                    message: e.Message);

                TempData["Error"]          = e.Message;
                TempData["InnerException"] = e.InnerException?.Message;
                return(RedirectToAction("Error"));
            }
        }
예제 #3
0
        public void PngBase64UriShouldRetrieveCorrectValue()
        {
            byte[] pngBytes      = Conversion.UtfToBytes("PngData");
            var    yotiAttribute = new YotiAttribute <Image>(
                name: "selfie",
                value: new PngImage(pngBytes),
                anchors: null);

            string expectedString = string.Format("data:image/png;base64,{0}", Conversion.BytesToBase64(pngBytes));

            Assert.AreEqual(expectedString, yotiAttribute.GetValue().GetBase64URI());
        }
예제 #4
0
        public void GetValueShouldRetrieveImage()
        {
            byte[] imageBytes = Conversion.UtfToBytes("ImageValue");

            var yotiAttribute = new YotiAttribute <Image>("selfie", new JpegImage(imageBytes), null);

            var expectedImage = new JpegImage(imageBytes);

            string expectedBase64URI = string.Format("data:image/jpeg;base64,{0}", Conversion.BytesToBase64(imageBytes));
            Image  actualImage       = yotiAttribute.GetValue();

            Assert.IsTrue(new ImageComparer().Equals(expectedImage, actualImage));
            Assert.AreEqual(expectedBase64URI, actualImage.GetBase64URI());
        }
예제 #5
0
        public void GetAttributeByNameShouldRetrieveDatetime()
        {
            DateTime value            = new DateTime(1990, 1, 13);
            var      initialAttribute = new YotiAttribute <DateTime>(
                name: Constants.UserProfile.DateOfBirthAttribute,
                value: value,
                anchors: null);

            YotiProfile userProfile = TestTools.Profile.CreateUserProfileWithSingleAttribute(initialAttribute);

            YotiAttribute <DateTime> dobAttribute = userProfile.GetAttributeByName <DateTime>(Constants.UserProfile.DateOfBirthAttribute);

            Assert.AreSame(initialAttribute, dobAttribute);
            Assert.AreEqual(value, dobAttribute.GetValue());
        }
예제 #6
0
        public void ShouldRetrieveIntAttribute()
        {
            string intAttributeName = "intAttributeName";
            int    intValue         = 92387;
            var    initialAttribute = new YotiAttribute <int>(
                intAttributeName,
                intValue,
                anchors: null);

            YotiProfile         yotiProfile  = TestTools.Profile.CreateUserProfileWithSingleAttribute(initialAttribute);
            YotiAttribute <int> intAttribute = yotiProfile.GetAttributeByName <int>(intAttributeName);
            YotiAttribute <int> intAttributeFromCollection = yotiProfile.GetAttributesByName <int>(intAttributeName).Single();

            Assert.AreEqual(intValue, intAttribute.GetValue());
            Assert.AreEqual(intValue, intAttributeFromCollection.GetValue());
        }
예제 #7
0
        public void GetAttributeByNameShouldRetrieveImage()
        {
            Image imageValue = new PngImage(Encoding.UTF8.GetBytes("Value"));

            var initialAttribute = new YotiAttribute <Image>(
                name: Constants.UserProfile.SelfieAttribute,
                value: imageValue,
                anchors: null);

            YotiProfile userProfile = new YotiProfile();

            userProfile.Add(initialAttribute);

            YotiAttribute <Image> imageAttribute = userProfile.GetAttributeByName <Image>(Constants.UserProfile.SelfieAttribute);

            Assert.AreEqual(imageValue, imageAttribute.GetValue());
        }
예제 #8
0
        public void GetAttributeByNameShouldRetrieveBool()
        {
            bool   boolValue     = true;
            string attributeName = "Bool";

            var initialAttribute = new YotiAttribute <bool>(
                name: attributeName,
                value: boolValue,
                anchors: null);

            YotiProfile userProfile = new YotiProfile();

            userProfile.Add(initialAttribute);

            YotiAttribute <bool> boolAttribute = userProfile.GetAttributeByName <bool>(attributeName);

            Assert.AreEqual(boolValue, boolAttribute.GetValue());
        }
예제 #9
0
        public AgeVerification(YotiAttribute <string> derivedAttribute)
        {
            if (derivedAttribute == null)
            {
                throw new ArgumentNullException(nameof(derivedAttribute));
            }

            string attributeName = derivedAttribute.GetName();

            if (!Regex.IsMatch(attributeName, expectedFormatRegex))
            {
                throw new InvalidOperationException(
                          $"{nameof(attributeName)} {Properties.Resources.FormatMismatch} '{expectedFormatRegex}'");
            }

            _derivedAttribute = derivedAttribute;

            string[] split = attributeName.Split(':');
            _checkPerformed = split[0];
            _ageVerified    = int.Parse(split[1], new CultureInfo("en-GB"));
            _result         = bool.Parse(derivedAttribute.GetValue());
        }