/// <summary> /// Add an item to a Store request. /// </summary> /// <param name="idUri">The namespace URI for this item.</param> /// <param name="alias">A short alias for this item.</param> /// <param name="values">One or more values to record in this item.</param> /// <exception cref="InvalidOperationException">Attempted to add store item in Fetch mode.</exception> public void AddStoreItem(Uri idUri, string alias, params string[] values) { if (Mode == AttributeExchangeMode.Fetch) { throw new InvalidOperationException("Incorrect Mode. Must set Mode to AttributeExchangeMode.Store to add store items."); } AttributeExchangeItem aei = new AttributeExchangeItem(); aei.IdUri = idUri; aei.Alias = alias; aei.Count = values.Length; aei.Values = values; _RequestData.Add(aei); }
/// <summary> /// Decode data returned from a fetch request /// </summary> /// <param name="arguments">Request data that holds the data to decode.</param> /// <returns>An array of AttributeExchangeItem objects.</returns> internal static AttributeExchangeItem[] DecodeUserData(NameValueCollection arguments) { NameValueCollection ds = Utility.GetExtNamespaceAliases(arguments); if (ds[ProtocolUri.AttributeExchange1Dot0.AbsoluteUri] == null) { return null; } string p = ds[ProtocolUri.AttributeExchange1Dot0.AbsoluteUri]; string prefix = "openid." + p + "."; List<AttributeExchangeItem> list = new List<AttributeExchangeItem>(); List<string> keys = new List<string>(); foreach (string k in arguments.Keys) { keys.Add(k); } foreach (string s in arguments.Keys) { if (s != null && s.StartsWith(prefix + "type.", StringComparison.OrdinalIgnoreCase)) { AttributeExchangeItem aei = new AttributeExchangeItem(); // Determine alias aei.Alias = s.Substring((prefix + "type.").Length); // Get URI aei.IdUri = new Uri(arguments[s]); bool useCount = false; // Determine value count if (keys.Contains(prefix + "count." + aei.Alias)) { aei.Count = Convert.ToInt32(arguments[prefix + "count." + aei.Alias], CultureInfo.InvariantCulture); useCount = true; } else { aei.Count = 1; useCount = false; } // Get values List<string> values = new List<string>(); for (int i = 1; i <= aei.Count; i++) { if (useCount) { values.Add(arguments[prefix + "value." + aei.Alias + "." + i]); } else { values.Add(arguments[prefix + "value." + aei.Alias]); } } aei.Values = values.ToArray(); list.Add(aei); } } return list.ToArray(); }
/// <summary> /// Add an item to a Fetch request. /// </summary> /// <param name="idUri">The namespace URI for this item.</param> /// <param name="alias">A short alias to use for this item. Use the same alias to retrieve data from the OpenIdUser object.</param> /// <param name="count">The number of values to return, if more than one value is recorded at the OpenID Provider.</param> /// <param name="required">Whether or not a response for this item is required.</param> /// <exception cref="InvalidOperationException">Attempted to add fetch item when it Store mode.</exception> public void AddFetchItem(Uri idUri, string alias, int count, bool required) { if (Mode == AttributeExchangeMode.Store) { throw new InvalidOperationException("Incorrect Mode. Must set Mode to AttributeExchangeMode.Fetch to add fetch items."); } AttributeExchangeItem aei = new AttributeExchangeItem(); aei.IdUri = idUri; aei.Alias = alias; aei.Count = count; aei.Required = required; _RequestData.Add(aei); }