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); }
internal static void SetAddressToBeFormattedAddressIfNull(YotiProfile yotiProfile) { YotiAttribute <Dictionary <string, JToken> > structuredPostalAddress = yotiProfile.StructuredPostalAddress; if (yotiProfile.Address == null && structuredPostalAddress != null) { structuredPostalAddress.GetValue().TryGetValue("formatted_address", out JToken formattedAddressJToken); if (formattedAddressJToken != null) { var addressAttribute = new YotiAttribute <string>( name: Constants.UserProfile.PostalAddressAttribute, value: formattedAddressJToken.ToString(), anchors: structuredPostalAddress.GetAnchors()); yotiProfile.Add(addressAttribute); } } }
private void SetAddressToBeFormattedAddressIfNull() { YotiAttribute <IEnumerable <Dictionary <string, JToken> > > structuredPostalAddress = _yotiProfile.StructuredPostalAddress; if (_yotiProfile.Address == null && structuredPostalAddress != null) { PropertyInfo addressPropertyInfo = GetProfilePropertyByProtobufName("postal_address"); Dictionary <string, JToken> jsonValue = structuredPostalAddress.GetJsonValue(); jsonValue.TryGetValue("formatted_address", out JToken formattedAddressJToken); if (formattedAddressJToken != null) { string formattedAddress = formattedAddressJToken.ToString(); SetStringAttribute( addressPropertyInfo, formattedAddress, structuredPostalAddress.GetAnchors()); _yotiUserProfile.Address = formattedAddress; } } }
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(); }