コード例 #1
0
 public void Startup()
 {
     _yotiProfile     = new YotiProfile();
     _yotiUserProfile = new YotiUserProfile();
     _activity        = new Activity(_yotiProfile, _yotiUserProfile);
     _attributeList   = new AttrpubapiV1.AttributeList();
 }
コード例 #2
0
        public ActivityDetails HandleSuccessfulResponse(AsymmetricCipherKeyPair keyPair, Response response)
        {
            ProfileDO parsedResponse = JsonConvert.DeserializeObject <ProfileDO>(response.Content);

            if (parsedResponse.receipt == null)
            {
                return(new ActivityDetails
                {
                    Outcome = ActivityOutcome.Failure
                });
            }
            else if (parsedResponse.receipt.sharing_outcome != "SUCCESS")
            {
                return(new ActivityDetails
                {
                    Outcome = ActivityOutcome.SharingFailure
                });
            }
            else
            {
                ReceiptDO receipt = parsedResponse.receipt;

                AttrpubapiV1.AttributeList attributes = CryptoEngine.DecryptCurrentUserReceipt(
                    parsedResponse.receipt.wrapped_receipt_key,
                    parsedResponse.receipt.other_party_profile_content,
                    keyPair);

                _yotiUserProfile.Id = parsedResponse.receipt.remember_me_id;
                _yotiProfile.Id     = parsedResponse.receipt.remember_me_id;

                AddAttributesToProfile(attributes);

                return(new ActivityDetails
                {
                    Outcome = ActivityOutcome.Success,
                    UserProfile = _yotiUserProfile,
                    Profile = _yotiProfile
                });
            }
        }
コード例 #3
0
        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();
        }