예제 #1
0
 internal ActivityDetails(string rememberMeId, string parentRememberMeId, DateTime?timestamp, YotiProfile yotiProfile, ApplicationProfile applicationProfile, string receiptId, ExtraData extraData)
 {
     RememberMeId       = rememberMeId;
     ParentRememberMeId = parentRememberMeId;
     Timestamp          = timestamp;
     Profile            = yotiProfile;
     ApplicationProfile = applicationProfile;
     ReceiptId          = receiptId;
     ExtraData          = extraData;
 }
        public static ActivityDetails HandleResponse(AsymmetricCipherKeyPair keyPair, string responseContent)
        {
            if (string.IsNullOrEmpty(responseContent))
            {
                throw new YotiProfileException(Properties.Resources.NullOrEmptyResponseContent);
            }

            ProfileDO parsedResponse = JsonConvert.DeserializeObject <ProfileDO>(responseContent);

            if (parsedResponse.Receipt == null)
            {
                throw new YotiProfileException(Properties.Resources.NullParsedResponse);
            }
            else if (parsedResponse.Receipt.SharingOutcome != "SUCCESS")
            {
                throw new YotiProfileException(
                          $"The share was not successful, sharing_outcome: '{parsedResponse.Receipt.SharingOutcome}'");
            }

            ReceiptDO receipt = parsedResponse.Receipt;

            var userProfile = new YotiProfile(
                ParseProfileContent(keyPair, receipt.WrappedReceiptKey, receipt.OtherPartyProfileContent));

            SetAddressToBeFormattedAddressIfNull(userProfile);

            var applicationProfile = new ApplicationProfile(
                ParseProfileContent(keyPair, receipt.WrappedReceiptKey, receipt.ProfileContent));

            ExtraData extraData = new ExtraData();

            if (!string.IsNullOrEmpty(parsedResponse.Receipt.ExtraDataContent))
            {
                extraData = CryptoEngine.DecryptExtraData(
                    receipt.WrappedReceiptKey,
                    parsedResponse.Receipt.ExtraDataContent,
                    keyPair);
            }

            DateTime?timestamp = null;

            if (receipt.Timestamp != null &&
                DateTime.TryParseExact(
                    receipt.Timestamp,
                    "yyyy-MM-ddTHH:mm:ssZ",
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.AdjustToUniversal,
                    out DateTime parsedDate))
            {
                timestamp = parsedDate;
            }

            return(new ActivityDetails(parsedResponse.Receipt.RememberMeId, parsedResponse.Receipt.ParentRememberMeId, timestamp, userProfile, applicationProfile, parsedResponse.Receipt.ReceiptId, extraData));
        }
        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);
                }
            }
        }
예제 #4
0
        private static void HandleOtherAttributes(YotiProfile profile, AttrpubapiV1.Attribute attribute, byte[] data)
        {
            profile.OtherAttributes = new Dictionary <string, YotiAttributeValue>();

            switch (attribute.ContentType)
            {
            case AttrpubapiV1.ContentType.Date:
                profile.OtherAttributes.Add(
                    attribute.Name,
                    new YotiAttributeValue(TypeEnum.Date, data));
                break;

            case AttrpubapiV1.ContentType.String:
                profile.OtherAttributes.Add(
                    attribute.Name,
                    new YotiAttributeValue(TypeEnum.Text, data));
                break;

            case AttrpubapiV1.ContentType.Jpeg:
                profile.OtherAttributes.Add(
                    attribute.Name,
                    new YotiAttributeValue(TypeEnum.Jpeg, data));
                break;

            case AttrpubapiV1.ContentType.Png:
                profile.OtherAttributes.Add(
                    attribute.Name,
                    new YotiAttributeValue(TypeEnum.Png, data));
                break;

            case AttrpubapiV1.ContentType.Json:
                profile.OtherAttributes.Add(
                    attribute.Name,
                    new YotiAttributeValue(TypeEnum.Json, data));
                break;

            // do not return attributes with undefined content types
            case AttrpubapiV1.ContentType.Undefined:
            default:
                break;
            }
        }
예제 #5
0
 public Activity(YotiProfile yotiProfile, YotiUserProfile yotiUserProfile)
 {
     _yotiUserProfile = yotiUserProfile;
     _yotiProfile     = yotiProfile;
 }