private void SetDateAttribute(PropertyInfo propertyInfo, byte[] value, List <Anchor> anchors)
        {
            var yotiAttributeValue = new YotiAttributeValue(TypeEnum.Date, value);
            var yotiAttribute      = new YotiAttribute <DateTime?>(
                propertyInfo.Name,
                yotiAttributeValue,
                anchors);

            propertyInfo.SetValue(_yotiProfile, yotiAttribute);
        }
        private void SetStringAttribute(PropertyInfo propertyInfo, string value, List <Anchor> anchors)
        {
            var yotiAttributeValue = new YotiAttributeValue(TypeEnum.Text, value);
            var yotiAttribute      = new YotiAttribute <string>(
                propertyInfo.Name,
                yotiAttributeValue,
                anchors);

            propertyInfo.SetValue(_yotiProfile, yotiAttribute);
        }
        public static YotiAttribute <object> ConvertAttribute(AttrpubapiV1.Attribute attribute)
        {
            YotiAttributeValue value;

            switch (attribute.ContentType)
            {
            case ContentType.String:
                value = new YotiAttributeValue(TypeEnum.Text, attribute.Value.ToByteArray());
                break;

            case ContentType.Date:
                value = new YotiAttributeValue(TypeEnum.Date, attribute.Value.ToByteArray());
                break;

            case ContentType.Jpeg:
                value = new YotiAttributeValue(TypeEnum.Jpeg, attribute.Value.ToByteArray());
                break;

            case ContentType.Png:
                value = new YotiAttributeValue(TypeEnum.Png, attribute.Value.ToByteArray());
                break;

            case ContentType.Json:
                value = new YotiAttributeValue(TypeEnum.Json, attribute.Value.ToByteArray());
                break;

            case ContentType.Undefined:
                // do not return attributes with undefined content types
                return(null);

            default:
                return(null);
            }

            return(new YotiAttribute <object>(
                       attribute.Name,
                       value,
                       ParseAnchors(attribute)));
        }
Exemple #4
0
 public YotiAttribute(string name, YotiAttributeValue value, List <Anchor> anchors)
 {
     _name    = name;
     Value    = value;
     _anchors = anchors;
 }
Exemple #5
0
 public YotiAttribute(string name, YotiAttributeValue value)
 {
     _name = name;
     Value = value;
 }
 public YotiImageAttribute(string name, YotiAttributeValue value) : base(name, value)
 {
 }
 public YotiImageAttribute(string name, YotiAttributeValue value, List <Anchor> anchors) : base(name, value, anchors)
 {
 }
        internal void AddAttributesToProfile(AttrpubapiV1.AttributeList attributes)
        {
            foreach (AttrpubapiV1.Attribute attribute in attributes.Attributes)
            {
                YotiAttribute <object> yotiAttribute = AttributeConverter.ConvertAttribute(attribute);
                byte[] byteValue = attribute.Value.ToByteArray();

                if (yotiAttribute == null)
                {
                    HandleOtherAttributes(_yotiProfile, attribute, byteValue);
                    return;
                }

                string stringValue = Conversion.BytesToUtf8(byteValue);

                LegacyAddAttribute(attribute, byteValue);

                PropertyInfo propertyInfo = GetProfilePropertyByProtobufName(yotiAttribute.GetName());

                if (propertyInfo == null)
                {
                    HandleOtherAttributes(_yotiProfile, attribute, byteValue);
                    return;
                }

                List <Yoti.Auth.Anchors.Anchor> anchors = yotiAttribute.GetAnchors();

                switch (attribute.ContentType)
                {
                case AttrpubapiV1.ContentType.Json:
                    if (attribute.Name == YotiConstants.AttributeStructuredPostalAddress)
                    {
                        var structuredPostalAddressAttributeValue = new YotiAttributeValue(TypeEnum.Json, byteValue);
                        var structuredPostalAddressAttribute      = new YotiAttribute <IEnumerable <Dictionary <string, JToken> > >(
                            YotiConstants.AttributeStructuredPostalAddress,
                            structuredPostalAddressAttributeValue,
                            anchors);

                        _yotiProfile.StructuredPostalAddress = structuredPostalAddressAttribute;
                        break;
                    }
                    else
                    {
                        HandleOtherAttributes(_yotiProfile, attribute, byteValue);
                    }
                    break;

                case AttrpubapiV1.ContentType.String:
                    if (yotiAttribute.GetName().StartsWith(YotiConstants.AttributeAgeOver) ||
                        yotiAttribute.GetName().StartsWith(YotiConstants.AttributeAgeUnder))
                    {
                        bool parsed = Boolean.TryParse(stringValue, out bool AgeVerified);

                        if (!parsed)
                        {
                            throw new FormatException(
                                      String.Format(
                                          "'{0}' byte value was unable to be parsed into a bool",
                                          byteValue));
                        }

                        var AgeVerifiedAttributeValue = new YotiAttributeValue(TypeEnum.Bool, byteValue);
                        _yotiProfile.AgeVerified = new YotiAttribute <bool?>(
                            propertyInfo.Name,
                            AgeVerifiedAttributeValue,
                            anchors);

                        break;
                    }

                    SetStringAttribute(propertyInfo, stringValue, anchors);
                    break;

                case AttrpubapiV1.ContentType.Jpeg:
                    var jpegYotiAttributeValue = new YotiAttributeValue(TypeEnum.Jpeg, byteValue);
                    _yotiProfile.Selfie = new YotiImageAttribute <Image>(
                        propertyInfo.Name,
                        jpegYotiAttributeValue,
                        anchors);
                    break;

                case AttrpubapiV1.ContentType.Png:
                    var pngYotiAttributeValue = new YotiAttributeValue(TypeEnum.Png, byteValue);
                    _yotiProfile.Selfie = new YotiImageAttribute <Image>(
                        propertyInfo.Name,
                        pngYotiAttributeValue,
                        anchors);
                    break;

                case AttrpubapiV1.ContentType.Date:

                    DateTime date;
                    if (DateTime.TryParseExact(stringValue, "yyyy-MM-dd", CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out date))
                    {
                        SetDateAttribute(propertyInfo, byteValue, anchors);
                    }
                    break;

                default:
                    HandleOtherAttributes(_yotiProfile, attribute, byteValue);
                    break;
                }
            }

            SetAddressToBeFormattedAddressIfNull();
        }