/// <summary> /// Accepts a claimed identifier and returns /// the normalized identifier, and an end-point URL. /// </summary> /// <param name="openid">String containing claimed identifier.</param> /// <returns>A populated NormalizationEntry object, or null if the identitifer cannot /// be processed by this plug-in.</returns> public NormalizationEntry ProcessId(string openid) { NormalizationEntry ne = new NormalizationEntry(); if (openid.StartsWith("http://xri.net/", StringComparison.OrdinalIgnoreCase)) { openid = openid.Substring(15); } if (openid.StartsWith("https://xri.net/", StringComparison.OrdinalIgnoreCase)) { openid = openid.Substring(16); } foreach (string prefix in Prefixes) { if (openid.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { if (prefix.Length == 1) { ne.FriendlyId = openid; ne.NormalizedId = openid; ne.DiscoveryUrl = new Uri("https://xri.net/" + openid); } else { string a = openid; a = a.Substring(prefix.Length, a.Length - prefix.Length); ne.FriendlyId = a; ne.NormalizedId = a; ne.DiscoveryUrl = new Uri("https://xri.net/" + a); } } } if (ne.DiscoveryUrl == null) { return null; } return ne; }
/// <summary> /// Processes a claimed identifier and returns a normalized ID and an endpoint URL. /// </summary> /// <param name="openid">Claimed identifier to process.</param> /// <returns>A populated NormalizationEntry object, or null if the identitifer cannot /// be processed by this plug-in.</returns> public NormalizationEntry ProcessId(string openid) { NormalizationEntry ne = new NormalizationEntry(); if (openid.StartsWith("https://xri.net/", StringComparison.OrdinalIgnoreCase) || openid.StartsWith("http://xri.net/", StringComparison.OrdinalIgnoreCase)) { return null; } foreach (string prefix in _Prefixes) { if (openid.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { string a = openid; a = a.Substring(prefix.Length, a.Length - prefix.Length); ne.FriendlyId = a.Trim('/'); ne.DiscoveryUrl = new Uri(openid); ne.NormalizedId = ne.DiscoveryUrl.AbsoluteUri; return ne; } } try { ne.FriendlyId = openid.Trim('/'); ne.DiscoveryUrl = new Uri("http://" + openid); ne.NormalizedId = ne.DiscoveryUrl.AbsoluteUri; } catch (UriFormatException) { return null; } return ne; }
/// <summary> /// Converts a supplied OpenID into two distinct entities - a normalized name and a URI /// </summary> /// <param name="openid">OpenID to normalize</param> /// <param name="plugins">IDiscovery plugins to use to process the OpenID</param> /// <returns>A populated NormalizationEntry object.</returns> internal static NormalizationEntry Normalize(string openid, IEnumerable<IDiscovery> plugins) { if (String.IsNullOrEmpty(openid)) { throw new ArgumentNullException("openid"); } if (plugins == null) { throw new ArgumentNullException("plugins"); } NormalizationEntry result = new NormalizationEntry(); // Loop through the registered Discovery Plugins // and attempt to get a processed ID. foreach (IDiscovery disc in plugins) { result = disc.ProcessId(openid); if (result != null) { break; } } return result; }