/// <summary>
        /// Generates the OpenID Providers that are capable of asserting ownership
        /// of a particular XRI claimed identifier.
        /// </summary>
        /// <param name="xrds">The XrdsDocument instance to use in this process.</param>
        /// <param name="userSuppliedIdentifier">The i-name supplied by the user.</param>
        /// <returns>A sequence of the providers that can assert ownership of the given identifier.</returns>
        private static IEnumerable <IdentifierDiscoveryResult> GenerateClaimedIdentifierServiceEndpoints(this IEnumerable <XrdElement> xrds, XriIdentifier userSuppliedIdentifier)
        {
            // Cannot use code contracts because this method uses yield return.
            ////Contract.Requires<ArgumentNullException>(xrds != null);
            ////Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null);
            ErrorUtilities.VerifyArgumentNotNull(xrds, "xrds");

            foreach (var service in xrds.FindClaimedIdentifierServices())
            {
                foreach (var uri in service.UriElements)
                {
                    // spec section 7.3.2.3 on Claimed Id -> CanonicalID substitution
                    if (service.Xrd.CanonicalID == null)
                    {
                        break; // skip on to next service
                    }
                    ErrorUtilities.VerifyProtocol(service.Xrd.IsCanonicalIdVerified, XrdsStrings.CIDVerificationFailed, userSuppliedIdentifier);

                    // In the case of XRI names, the ClaimedId is actually the CanonicalID.
                    var claimedIdentifier = new XriIdentifier(service.Xrd.CanonicalID);
                    var providerEndpoint  = new ProviderEndpointDescription(uri.Uri, service.TypeElementUris);
                    yield return(IdentifierDiscoveryResult.CreateForClaimedIdentifier(claimedIdentifier, userSuppliedIdentifier, service.ProviderLocalIdentifier, providerEndpoint, service.Priority, uri.Priority));
                }
            }
        }
Esempio n. 2
0
 public static Identifier Parse(string identifier)
 {
     if (XriIdentifier.IsValidXri(identifier))
     {
         return(new XriIdentifier(identifier));
     }
     else
     {
         return(new UriIdentifier(identifier));
     }
 }
        /// <summary>
        /// Tests equality between this XRI and another XRI.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">
        /// The <paramref name="obj"/> parameter is null.
        /// </exception>
        public override bool Equals(object obj)
        {
            XriIdentifier other = obj as XriIdentifier;

            if (obj != null && other == null && Identifier.EqualityOnStrings)
            { // test hook to enable MockIdentifier comparison
                string objString = obj.ToString();
                ErrorUtilities.VerifyInternal(!string.IsNullOrEmpty(objString), "Identifier.ToString() returned a null or empty string.");
                other = Identifier.Parse(objString) as XriIdentifier;
            }
            if (other == null)
            {
                return(false);
            }
            return(this.CanonicalXri == other.CanonicalXri);
        }
        /// <summary>
        /// Creates the service endpoints described in this document, useful for requesting
        /// authentication of one of the OpenID Providers that result from it.
        /// </summary>
        /// <param name="xrds">The XrdsDocument instance to use in this process.</param>
        /// <param name="userSuppliedIdentifier">The user-supplied i-name that was used to discover this XRDS document.</param>
        /// <returns>A sequence of OpenID Providers that can assert ownership of the canonical ID given in this document.</returns>
        internal static IEnumerable <IdentifierDiscoveryResult> CreateServiceEndpoints(this IEnumerable <XrdElement> xrds, XriIdentifier userSuppliedIdentifier)
        {
            var endpoints = new List <IdentifierDiscoveryResult>();

            endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier));
            endpoints.AddRange(xrds.GenerateClaimedIdentifierServiceEndpoints(userSuppliedIdentifier));
            return(endpoints);
        }
Esempio n. 5
0
 public static bool IsValid(string identifier)
 {
     return(XriIdentifier.IsValidXri(identifier) || UriIdentifier.IsValidUri(identifier));
 }