public void CtorGoodXriSecure()
 {
     var xri = new XriIdentifier(this.goodXri, true);
     Assert.AreEqual(this.goodXri, xri.OriginalXri);
     Assert.AreEqual(this.goodXri, xri.CanonicalXri); // assumes 'goodXri' is canonical already
     Assert.IsTrue(xri.IsDiscoverySecureEndToEnd);
 }
Exemple #2
0
        /// <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.
            ////Requires.NotNull(xrds, "xrds");
            ////			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)
                    {
                        Logger.Yadis.WarnFormat(XrdsStrings.MissingCanonicalIDElement, userSuppliedIdentifier);
                        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));
                }
            }
        }
Exemple #3
0
        /// <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 (other == null)
            {
                return(false);
            }
            return(this.CanonicalXri == other.CanonicalXri);
        }
		/// <summary>
		/// Downloads the XRDS document for this XRI.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		/// <param name="requestHandler">The request handler.</param>
		/// <returns>The XRDS document.</returns>
		private static XrdsDocument DownloadXrds(XriIdentifier identifier, IDirectWebRequestHandler requestHandler) {
			Requires.NotNull(identifier, "identifier");
			Requires.NotNull(requestHandler, "requestHandler");
			Contract.Ensures(Contract.Result<XrdsDocument>() != null);
			XrdsDocument doc;
			using (var xrdsResponse = Yadis.Request(requestHandler, GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd)) {
				doc = new XrdsDocument(XmlReader.Create(xrdsResponse.ResponseStream));
			}
			ErrorUtilities.VerifyProtocol(doc.IsXrdResolutionSuccessful, OpenIdStrings.XriResolutionFailed);
			return doc;
		}
		/// <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) {
			Requires.NotNull(xrds, "xrds");
			Requires.NotNull(userSuppliedIdentifier, "userSuppliedIdentifier");

			var endpoints = new List<IdentifierDiscoveryResult>();
			endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier));
			endpoints.AddRange(xrds.GenerateClaimedIdentifierServiceEndpoints(userSuppliedIdentifier));
			Logger.Yadis.DebugFormat("Total services discovered in XRDS: {0}", endpoints.Count);
			Logger.Yadis.Debug(endpoints.ToStringDeferred(true));
			return endpoints;
		}
		/// <summary>
		/// Downloads the XRDS document for this XRI.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		/// <param name="requestHandler">The request handler.</param>
		/// <returns>The XRDS document.</returns>
		private static XrdsDocument DownloadXrds(XriIdentifier identifier, IDirectWebRequestHandler requestHandler) {
			Requires.NotNull(identifier, "identifier");
			Requires.NotNull(requestHandler, "requestHandler");
			XrdsDocument doc;
			using (var xrdsResponse = Yadis.Request(requestHandler, GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd)) {
				var readerSettings = MessagingUtilities.CreateUntrustedXmlReaderSettings();
				doc = new XrdsDocument(XmlReader.Create(xrdsResponse.ResponseStream, readerSettings));
			}
			ErrorUtilities.VerifyProtocol(doc.IsXrdResolutionSuccessful, OpenIdStrings.XriResolutionFailed);
			return doc;
		}
Exemple #7
0
 public static Identifier Parse(string identifier)
 {
     ErrorUtilities.VerifyArgumentNotNull(identifier, "identifier");
     if (XriIdentifier.IsValidXri(identifier))
     {
         return(new XriIdentifier(identifier));
     }
     else
     {
         return(new UriIdentifier(identifier));
     }
 }
        /// <summary>
        /// Downloads the XRDS document for this XRI.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="requestHandler">The request handler.</param>
        /// <returns>The XRDS document.</returns>
        private static XrdsDocument DownloadXrds(XriIdentifier identifier, IDirectWebRequestHandler requestHandler)
        {
            Requires.NotNull(identifier, "identifier");
            Requires.NotNull(requestHandler, "requestHandler");
            Contract.Ensures(Contract.Result <XrdsDocument>() != null);
            XrdsDocument doc;

            using (var xrdsResponse = Yadis.Request(requestHandler, GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd)) {
                doc = new XrdsDocument(XmlReader.Create(xrdsResponse.ResponseStream));
            }
            ErrorUtilities.VerifyProtocol(doc.IsXrdResolutionSuccessful, OpenIdStrings.XriResolutionFailed);
            return(doc);
        }
        /// <summary>
        /// Downloads the XRDS document for this XRI.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="requestHandler">The request handler.</param>
        /// <returns>The XRDS document.</returns>
        private static XrdsDocument DownloadXrds(XriIdentifier identifier, IDirectWebRequestHandler requestHandler)
        {
            Requires.NotNull(identifier, "identifier");
            Requires.NotNull(requestHandler, "requestHandler");
            XrdsDocument doc;

            using (var xrdsResponse = Yadis.Request(requestHandler, GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd)) {
                var readerSettings = MessagingUtilities.CreateUntrustedXmlReaderSettings();
                doc = new XrdsDocument(XmlReader.Create(xrdsResponse.ResponseStream, readerSettings));
            }
            ErrorUtilities.VerifyProtocol(doc.IsXrdResolutionSuccessful, OpenIdStrings.XriResolutionFailed);
            return(doc);
        }
Exemple #10
0
        public static Identifier Parse(string identifier)
        {
            Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(identifier));
            Contract.Ensures(Contract.Result <Identifier>() != null);

            if (XriIdentifier.IsValidXri(identifier))
            {
                return(new XriIdentifier(identifier));
            }
            else
            {
                return(new UriIdentifier(identifier));
            }
        }
Exemple #11
0
        /// <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<ServiceEndpoint> CreateServiceEndpoints(this XrdsDocument xrds, XriIdentifier userSuppliedIdentifier)
        {
            Contract.Requires(xrds != null);
            Contract.Requires(userSuppliedIdentifier != null);
            Contract.Ensures(Contract.Result<IEnumerable<ServiceEndpoint>>() != null);
            var endpoints = new List<ServiceEndpoint>();
            endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier));

            // If any OP Identifier service elements were found, we must not proceed
            // to return any Claimed Identifier services.
            if (endpoints.Count == 0) {
                endpoints.AddRange(xrds.GenerateClaimedIdentifierServiceEndpoints(userSuppliedIdentifier));
            }
            Logger.Yadis.DebugFormat("Total services discovered in XRDS: {0}", endpoints.Count);
            Logger.Yadis.Debug(endpoints.ToStringDeferred(true));
            return endpoints;
        }
Exemple #13
0
        public static Identifier Parse(string identifier, bool serializeExactValue)
        {
            Requires.NotNullOrEmpty(identifier, "identifier");

            Identifier id;

            if (XriIdentifier.IsValidXri(identifier))
            {
                id = new XriIdentifier(identifier);
            }
            else
            {
                id = new UriIdentifier(identifier);
            }

            id.IsDeserializedInstance = serializeExactValue;
            return(id);
        }
Exemple #14
0
        public static Identifier Parse(string identifier, bool serializeExactValue)
        {
            Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(identifier));
            Contract.Ensures(Contract.Result <Identifier>() != null);

            Identifier id;

            if (XriIdentifier.IsValidXri(identifier))
            {
                id = new XriIdentifier(identifier);
            }
            else
            {
                id = new UriIdentifier(identifier);
            }

            id.IsDeserializedInstance = serializeExactValue;
            return(id);
        }
        /// <summary>
        /// Gets the URL from which this XRI's XRDS document may be downloaded.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <returns>The URI to HTTP GET from to get the services.</returns>
        private static Uri GetXrdsUrl(XriIdentifier identifier)
        {
            ErrorUtilities.VerifyProtocol(OpenIdElement.Configuration.XriResolver.Enabled, OpenIdStrings.XriResolutionDisabled);
            string xriResolverProxy = XriResolverProxyTemplate;

            if (identifier.IsDiscoverySecureEndToEnd)
            {
                // Indicate to xri.net that we require SSL to be used for delegated resolution
                // of community i-names.
                xriResolverProxy += ";https=true";
            }

            return(new Uri(
                       string.Format(
                           CultureInfo.InvariantCulture,
                           xriResolverProxy,
                           identifier,
                           OpenIdElement.Configuration.XriResolver.Proxy.Name)));
        }
Exemple #16
0
        /// <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 <ServiceEndpoint> GenerateClaimedIdentifierServiceEndpoints(this XrdsDocument xrds, XriIdentifier userSuppliedIdentifier)
        {
            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)
                    {
                        Logger.WarnFormat(XrdsStrings.MissingCanonicalIDElement, userSuppliedIdentifier);
                        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(ServiceEndpoint.CreateForClaimedIdentifier(claimedIdentifier, userSuppliedIdentifier, service.ProviderLocalIdentifier, providerEndpoint, service.Priority, uri.Priority));
                }
            }
        }
        /// <summary>
        /// Downloads the XRDS document for this XRI.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="hostFactories">The host factories.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The XRDS document.
        /// </returns>
        private static async Task <XrdsDocument> DownloadXrdsAsync(XriIdentifier identifier, IHostFactories hostFactories, CancellationToken cancellationToken)
        {
            Requires.NotNull(identifier, "identifier");
            Requires.NotNull(hostFactories, "hostFactories");

            XrdsDocument doc;

            using (var xrdsResponse = await Yadis.RequestAsync(GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd, hostFactories, cancellationToken)) {
                xrdsResponse.EnsureSuccessStatusCode();
                var readerSettings = MessagingUtilities.CreateUntrustedXmlReaderSettings();
                ErrorUtilities.VerifyProtocol(xrdsResponse.Content != null, "XRDS request \"{0}\" returned no response.", GetXrdsUrl(identifier));
                await xrdsResponse.Content.LoadIntoBufferAsync();

                using (var xrdsStream = await xrdsResponse.Content.ReadAsStreamAsync()) {
                    doc = new XrdsDocument(XmlReader.Create(xrdsStream, readerSettings));
                }
            }

            ErrorUtilities.VerifyProtocol(doc.IsXrdResolutionSuccessful, OpenIdStrings.XriResolutionFailed);
            return(doc);
        }
        /// <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)
        {
            Contract.Requires <ArgumentNullException>(xrds != null);
            Contract.Requires <ArgumentNullException>(userSuppliedIdentifier != null);
            Contract.Ensures(Contract.Result <IEnumerable <IdentifierDiscoveryResult> >() != null);

            var endpoints = new List <IdentifierDiscoveryResult>();

            endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier));
            endpoints.AddRange(xrds.GenerateClaimedIdentifierServiceEndpoints(userSuppliedIdentifier));
            Logger.Yadis.DebugFormat("Total services discovered in XRDS: {0}", endpoints.Count);
            Logger.Yadis.Debug(endpoints.ToStringDeferred(true));
            return(endpoints);
        }
Exemple #19
0
		public static Identifier Parse(string identifier, bool serializeExactValue) {
			Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(identifier));
			Contract.Ensures(Contract.Result<Identifier>() != null);

			Identifier id;
			if (XriIdentifier.IsValidXri(identifier)) {
				id = new XriIdentifier(identifier);
			} else {
				id = new UriIdentifier(identifier);
			}

			id.IsDeserializedInstance = serializeExactValue;
			return id;
		}
Exemple #20
0
        /// <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)
        {
            Requires.NotNull(xrds, "xrds");
            Requires.NotNull(userSuppliedIdentifier, "userSuppliedIdentifier");

            var endpoints = new List <IdentifierDiscoveryResult>();

            endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier));
            endpoints.AddRange(xrds.GenerateClaimedIdentifierServiceEndpoints(userSuppliedIdentifier));
            Logger.Yadis.DebugFormat("Total services discovered in XRDS: {0}", endpoints.Count);
            Logger.Yadis.Debug(endpoints.ToStringDeferred(true).ToString());
            return(endpoints);
        }
Exemple #21
0
        /// <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 <ServiceEndpoint> CreateServiceEndpoints(this XrdsDocument xrds, XriIdentifier userSuppliedIdentifier)
        {
            var endpoints = new List <ServiceEndpoint>();

            endpoints.AddRange(xrds.GenerateOPIdentifierServiceEndpoints(userSuppliedIdentifier));

            // If any OP Identifier service elements were found, we must not proceed
            // to return any Claimed Identifier services.
            if (endpoints.Count == 0)
            {
                endpoints.AddRange(xrds.GenerateClaimedIdentifierServiceEndpoints(userSuppliedIdentifier));
            }
            Logger.DebugFormat("Total services discovered in XRDS: {0}", endpoints.Count);
            Logger.Debug(endpoints.ToStringDeferred(true));
            return(endpoints);
        }
Exemple #22
0
 public static bool IsValid(string identifier)
 {
     return(XriIdentifier.IsValidXri(identifier) || UriIdentifier.IsValidUri(identifier));
 }
Exemple #23
0
 public static bool IsValid(string identifier)
 {
     Requires.NotNullOrEmpty(identifier, "identifier");
     return(XriIdentifier.IsValidXri(identifier) || UriIdentifier.IsValidUri(identifier));
 }
		/// <summary>
		/// Gets the URL from which this XRI's XRDS document may be downloaded.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		/// <returns>The URI to HTTP GET from to get the services.</returns>
		private static Uri GetXrdsUrl(XriIdentifier identifier) {
			ErrorUtilities.VerifyProtocol(OpenIdElement.Configuration.XriResolver.Enabled, OpenIdStrings.XriResolutionDisabled);
			string xriResolverProxy = XriResolverProxyTemplate;
			if (identifier.IsDiscoverySecureEndToEnd) {
				// Indicate to xri.net that we require SSL to be used for delegated resolution
				// of community i-names.
				xriResolverProxy += ";https=true";
			}

			return new Uri(
				string.Format(
					CultureInfo.InvariantCulture,
					xriResolverProxy,
					identifier,
					OpenIdElement.Configuration.XriResolver.Proxy.Name));
		}
		/// <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.
			////Requires.NotNull(xrds, "xrds");
			////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) {
						Logger.Yadis.WarnFormat(XrdsStrings.MissingCanonicalIDElement, userSuppliedIdentifier);
						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);
				}
			}
		}
		public void StripXriScheme() {
			var xri = new XriIdentifier("xri://" + this.goodXri);
			Assert.AreEqual("xri://" + this.goodXri, xri.OriginalXri);
			Assert.AreEqual(this.goodXri, xri.CanonicalXri);
		}
        /// <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<ServiceEndpoint> GenerateClaimedIdentifierServiceEndpoints(this XrdsDocument xrds, XriIdentifier userSuppliedIdentifier)
        {
            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) {
                        Logger.Yadis.WarnFormat(XrdsStrings.MissingCanonicalIDElement, userSuppliedIdentifier);
                        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 ServiceEndpoint.CreateForClaimedIdentifier(claimedIdentifier, userSuppliedIdentifier, service.ProviderLocalIdentifier, providerEndpoint, service.Priority, uri.Priority);
                }
            }
        }
		/// <summary>
		/// Downloads the XRDS document for this XRI.
		/// </summary>
		/// <param name="identifier">The identifier.</param>
		/// <param name="hostFactories">The host factories.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <returns>
		/// The XRDS document.
		/// </returns>
		private static async Task<XrdsDocument> DownloadXrdsAsync(XriIdentifier identifier, IHostFactories hostFactories, CancellationToken cancellationToken) {
			Requires.NotNull(identifier, "identifier");
			Requires.NotNull(hostFactories, "hostFactories");

			XrdsDocument doc;
			using (var xrdsResponse = await Yadis.RequestAsync(GetXrdsUrl(identifier), identifier.IsDiscoverySecureEndToEnd, hostFactories, cancellationToken)) {
				xrdsResponse.EnsureSuccessStatusCode();
				var readerSettings = MessagingUtilities.CreateUntrustedXmlReaderSettings();
				ErrorUtilities.VerifyProtocol(xrdsResponse.Content != null, "XRDS request \"{0}\" returned no response.", GetXrdsUrl(identifier));
				await xrdsResponse.Content.LoadIntoBufferAsync();
				using (var xrdsStream = await xrdsResponse.Content.ReadAsStreamAsync()) {
					doc = new XrdsDocument(XmlReader.Create(xrdsStream, readerSettings));
				}
			}

			ErrorUtilities.VerifyProtocol(doc.IsXrdResolutionSuccessful, OpenIdStrings.XriResolutionFailed);
			return doc;
		}
Exemple #29
0
 /// <summary>
 /// Performs discovery on THIS identifier, but generates <see cref="ServiceEndpoint"/>
 /// instances that treat another given identifier as the user-supplied identifier.
 /// </summary>
 /// <param name="requestHandler">The request handler to use in discovery.</param>
 /// <param name="userSuppliedIdentifier">The user supplied identifier, which may differ from this XRI instance due to multiple discovery steps.</param>
 /// <returns>A list of service endpoints offered for this identifier.</returns>
 internal IEnumerable <ServiceEndpoint> Discover(IDirectWebRequestHandler requestHandler, XriIdentifier userSuppliedIdentifier)
 {
     return(this.DownloadXrds(requestHandler).CreateServiceEndpoints(userSuppliedIdentifier));
 }
Exemple #30
0
 public static bool IsValid(string identifier)
 {
     Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(identifier));
     return(XriIdentifier.IsValidXri(identifier) || UriIdentifier.IsValidUri(identifier));
 }
 /// <summary>
 /// Performs discovery on THIS identifier, but generates <see cref="ServiceEndpoint"/>
 /// instances that treat another given identifier as the user-supplied identifier.
 /// </summary>
 /// <param name="requestHandler">The request handler to use in discovery.</param>
 /// <param name="userSuppliedIdentifier">The user supplied identifier, which may differ from this XRI instance due to multiple discovery steps.</param>
 /// <returns>A list of service endpoints offered for this identifier.</returns>
 internal IEnumerable<ServiceEndpoint> Discover(IDirectWebRequestHandler requestHandler, XriIdentifier userSuppliedIdentifier)
 {
     Contract.Requires(requestHandler != null);
     Contract.Requires(userSuppliedIdentifier != null);
     return this.DownloadXrds(requestHandler).CreateServiceEndpoints(userSuppliedIdentifier);
 }
		public void TrimFragment() {
			Identifier xri = new XriIdentifier(this.goodXri);
			Assert.AreSame(xri, xri.TrimFragment());
		}
Exemple #33
0
		public static Identifier Parse(string identifier, bool serializeExactValue) {
			Requires.NotNullOrEmpty(identifier, "identifier");

			Identifier id;
			if (XriIdentifier.IsValidXri(identifier)) {
				id = new XriIdentifier(identifier);
			} else {
				id = new UriIdentifier(identifier);
			}

			id.IsDeserializedInstance = serializeExactValue;
			return id;
		}