summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Hanselman <scotthanselman@gmail.com>2007-02-27 23:16:48 +0000
committerScott <scotthanselman@gmail.com>2007-02-27 23:16:48 +0000
commit617142523539e4a160c88ea8eafc8022df8045f4 (patch)
treefea30dbb011696f65841a63e2e4b4908808d297b
parentcad2020d518cb650c9525d801c3ccfcf0c75a025 (diff)
downloadDotNetOpenAuth-617142523539e4a160c88ea8eafc8022df8045f4.zip
DotNetOpenAuth-617142523539e4a160c88ea8eafc8022df8045f4.tar.gz
DotNetOpenAuth-617142523539e4a160c88ea8eafc8022df8045f4.tar.bz2
Chug chug...
git-svn-id: https://dotnetopenid.googlecode.com/svn/trunk@22 01efa1a6-402a-0410-b0ae-47b76eba00f0
-rw-r--r--source/Janrain.OpenId/Consumer/AuthRequest.cs89
-rw-r--r--source/Janrain.OpenId/Consumer/ServiceEndpoint.cs249
-rw-r--r--source/Janrain.OpenId/Janrain.OpenId.csproj13
-rw-r--r--source/Janrain.OpenId/Server/CheckIdRequest.cs65
-rw-r--r--source/Janrain.OpenId/Server/MalformedReturnUrl.cs28
-rw-r--r--source/Janrain.OpenId/Server/MalformedTrustRoot.cs21
-rw-r--r--source/Janrain.OpenId/Server/ProtocolException.cs2
-rw-r--r--source/Janrain.OpenId/Server/Response.cs2
-rw-r--r--source/Janrain.OpenId/Server/UntrustedReturnUrl.cs30
-rw-r--r--source/Janrain.OpenId/Util.cs11
-rw-r--r--source/Janrain.OpenId/Yadis/ServiceNode.cs57
-rw-r--r--source/Janrain.OpenId/Yadis/TypeNode.cs36
-rw-r--r--source/Janrain.OpenId/Yadis/UriNode.cs72
-rw-r--r--source/Janrain.OpenId/Yadis/Xrd.cs65
-rw-r--r--source/Janrain.OpenId/Yadis/XrdNode.cs46
15 files changed, 714 insertions, 72 deletions
diff --git a/source/Janrain.OpenId/Consumer/AuthRequest.cs b/source/Janrain.OpenId/Consumer/AuthRequest.cs
new file mode 100644
index 0000000..0afa4d3
--- /dev/null
+++ b/source/Janrain.OpenId/Consumer/AuthRequest.cs
@@ -0,0 +1,89 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Janrain.OpenId;
+using System.Collections.Specialized;
+
+namespace Janrain.OpenId.Consumer
+{
+ class AuthRequest
+ {
+ public enum Mode
+ {
+ IMMEDIATE,
+ SETUP
+ }
+
+ private string _token;
+ public string Token
+ {
+ get
+ {
+ return _token;
+ }
+ set
+ {
+ _token = value;
+ }
+ }
+
+ private NameValueCollection _extraArgs;
+ public NameValueCollection ExtraArgs
+ {
+ get
+ {
+ return _extraArgs;
+ }
+ }
+
+ private NameValueCollection _returnToArgs;
+ public NameValueCollection ReturnToArgs
+ {
+ get
+ {
+ return ReturnToArgs;
+ }
+ }
+
+ private Association _assoc;
+ private ServiceEndpoint _endpoint;
+
+ public AuthRequest(string token, Association assoc, ServiceEndpoint endpoint)
+ {
+ _token = token;
+ _assoc = assoc;
+ _endpoint = endpoint;
+
+ _extraArgs = new NameValueCollection();
+ _returnToArgs = new NameValueCollection();
+ }
+
+ public Uri CreateRedirect(string trustRoot, Uri returnTo, Mode mode)
+ {
+ string modeStr = String.Empty;
+ if (mode == Mode.IMMEDIATE)
+ modeStr = "checkid_immediate";
+ else if (mode == Mode.SETUP)
+ modeStr = "checkid_setup";
+
+ UriBuilder returnToBuilder = new UriBuilder(returnTo);
+ UriUtil.AppendQueryArgs(ref returnToBuilder, this.ReturnToArgs);
+
+ NameValueCollection qsArgs = new NameValueCollection();
+ qsArgs.Add("openid.mode", modeStr);
+ qsArgs.Add("openid.identity", this._endpoint.ServerId.AbsoluteUri); //TODO: breaks the Law of Demeter
+ qsArgs.Add("openid.return_to", new Uri(returnToBuilder.ToString(), true).AbsoluteUri); //TODO: obsolete, problem?
+ qsArgs.Add("openid.trust_root", trustRoot);
+
+ if (this._assoc != null)
+ qsArgs.Add("openid.assoc", this._assoc.Handle);
+
+ UriBuilder redir = new UriBuilder(this._endpoint.ServerUrl);
+ UriUtil.AppendQueryArgs(ref redir, qsArgs);
+ UriUtil.AppendQueryArgs(ref redir, this.ExtraArgs);
+ return new Uri(redir.ToString(), true);
+ }
+
+ }
+}
+
diff --git a/source/Janrain.OpenId/Consumer/ServiceEndpoint.cs b/source/Janrain.OpenId/Consumer/ServiceEndpoint.cs
new file mode 100644
index 0000000..274cdf3
--- /dev/null
+++ b/source/Janrain.OpenId/Consumer/ServiceEndpoint.cs
@@ -0,0 +1,249 @@
+using System;
+using System.Collections.Specialized;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+using Janrain.Yadis;
+
+namespace Janrain.OpenId.Consumer
+{
+ class ServiceEndpoint
+ {
+ public static readonly Uri OPENID_1_0_NS = new Uri("http://openid.net/xmlns/1.0");
+ public static readonly Uri OPENID_1_2_TYPE = new Uri("http://openid.net/signon/1.2");
+ public static readonly Uri OPENID_1_1_TYPE = new Uri("http://openid.net/signon/1.1");
+ public static readonly Uri OPENID_1_0_TYPE = new Uri("http://openid.net/signon/1.0");
+
+ public static readonly Uri[] OPENID_TYPE_URIS = { OPENID_1_2_TYPE,
+ OPENID_1_1_TYPE,
+ OPENID_1_0_TYPE };
+
+ private Uri _identityUrl;
+ public Uri IdentityUrl
+ {
+ get
+ {
+ return _identityUrl;
+ }
+ }
+
+ private Uri _serverUrl;
+ public Uri ServerUrl
+ {
+ get
+ {
+ return _serverUrl;
+ }
+ }
+
+ private Uri _delegateUrl;
+ public Uri DelegateUrl
+ {
+ get
+ {
+ return _delegateUrl;
+ }
+ }
+
+ private bool _usedYadis;
+ public bool UsedYadis
+ {
+ get
+ {
+ return _usedYadis;
+ }
+ }
+
+ Uri[] _typeUris;
+
+ public Uri ServerId
+ {
+ get
+ {
+ if (this._delegateUrl == null)
+ {
+ return this._identityUrl;
+ }
+ return this._delegateUrl;
+ }
+ }
+
+ public static Uri ExtractDelgate(ServiceNode serviceNode)
+ {
+ XmlNamespaceManager nsmgr = serviceNode.XmlNsManager;
+ nsmgr.PushScope();
+ nsmgr.AddNamespace("openid", OPENID_1_0_NS.AbsoluteUri);
+ XmlNodeList delegateNodes = serviceNode.Node.SelectNodes("./openid:Delegate", nsmgr);
+ Uri delegateUrl = null;
+ foreach (XmlNode delegateNode in delegateNodes)
+ {
+ try
+ {
+ delegateUrl = new Uri(delegateNode.InnerXml);
+ break;
+ }
+ catch (UriFormatException)
+ {
+ continue;
+ }
+ }
+ nsmgr.PopScope();
+ return delegateUrl;
+ }
+
+ internal ServiceEndpoint(Uri identityUrl, Uri serverUrl, Uri[] typeUris, Uri delegateUrl, bool usedYadis)
+ {
+ this._identityUrl = identityUrl;
+ this._serverUrl = serverUrl;
+ this._typeUris = typeUris;
+ this._delegateUrl = delegateUrl;
+ this._usedYadis = usedYadis;
+ }
+
+ //public ServiceEndpoint(Uri yadisUrl, UriNode uriNode)
+ //{
+ // ServiceNode localNode = uriNode.ServiceNode;
+ // Uri[] typeUris = Array.Copy()
+
+ // Uri[] matches =
+
+ // if ((matches.Length == 0) || (uriNode.Uri == null))
+ // {
+ // throw new ArgumentException("No matching openid type uris");
+ // }
+ // this._identityUrl = yadisUrl;
+ // this._serverUrl = uriNode.Uri;
+ // this._typeUris = _locals.___type_uris_1;
+ // this._delegateUrl = ExtractDelegate(localNode);
+ // this._usedYadis = true;
+ //}
+
+
+
+
+
+
+
+
+ }
+}
+
+
+/*
+namespace Janrain.OpenId.Consumer
+
+import System
+import System.Collections.Specialized
+import System.Xml
+#import Janrain.Util
+import Janrain.Yadis
+
+
+class ServiceEndpoint:
+ public static final OPENID_1_0_NS = Uri('http://openid.net/xmlns/1.0')
+ public static final OPENID_1_2_TYPE = Uri('http://openid.net/signon/1.2')
+ public static final OPENID_1_1_TYPE = Uri('http://openid.net/signon/1.1')
+ public static final OPENID_1_0_TYPE = Uri('http://openid.net/signon/1.0')
+
+ public static final OPENID_TYPE_URIS as (Uri) = (
+ OPENID_1_2_TYPE,
+ OPENID_1_1_TYPE,
+ OPENID_1_0_TYPE,
+ )
+
+ [Getter(IdentityUrl)]
+ identity_url as Uri
+
+ [Getter(ServerUrl)]
+ server_url as Uri
+
+ [Getter(DelegateUrl)]
+ delegate_url as Uri
+
+ [Getter(UsedYadis)]
+ used_yadis as bool
+
+ type_uris as (Uri)
+
+ ServerId:
+ get:
+ if self.delegate_url is null:
+ return self.identity_url
+ else:
+ return self.delegate_url
+
+ static def ExtractDelegate(service_node as ServiceNode):
+ nsmgr = service_node.XmlNsManager
+ nsmgr.PushScope()
+ nsmgr.AddNamespace("openid", OPENID_1_0_NS.AbsoluteUri)
+ delegate_nodes = service_node.Node.SelectNodes('./openid:Delegate', nsmgr)
+ delegate_url as Uri
+ for delegate_node as XmlNode in delegate_nodes:
+ try:
+ delegate_url = Uri(delegate_node.InnerXml)
+ break
+ except e as UriFormatException:
+ pass
+
+ nsmgr.PopScope()
+ return delegate_url
+
+ # Used for testing
+ internal def constructor(identity_url as Uri, server_url as Uri,
+ type_uris as (Uri), delegate_url as Uri,
+ used_yadis as bool):
+ self.identity_url = identity_url
+ self.server_url = server_url
+ self.type_uris = type_uris
+ self.delegate_url = delegate_url
+ self.used_yadis = used_yadis
+
+ def constructor(yadis_url as Uri, uri_node as UriNode):
+ service_node = uri_node.ServiceNode
+ type_uris as (Uri) = array(Uri, type_node.Uri \
+ for type_node in service_node.TypeNodes())
+
+ matches = array(Uri, type_uri for type_uri in type_uris \
+ if type_uri in OPENID_TYPE_URIS)
+
+ if not len(matches) or uri_node.Uri is null:
+ raise ArgumentException("No matching openid type uris")
+
+ self.identity_url = yadis_url
+ self.server_url = uri_node.Uri
+ self.type_uris = type_uris
+ self.delegate_url = ExtractDelegate(service_node)
+ self.used_yadis = true
+
+ def constructor(uri as Uri, html as string):
+ # Look for openid.server/delegate link rel tags
+ for attrs as NameValueCollection in ByteParser.HeadTagAttrs(
+ html, 'link'):
+ rel = attrs["rel"]
+ if rel is not null:
+ href = attrs["href"]
+ if href is not null:
+ if rel == "openid.server" and self.server_url is null:
+ try:
+ self.server_url = Uri(href)
+ except e as UriFormatException:
+ pass
+
+ if rel == "openid.delegate" and self.delegate_url is null:
+ try:
+ self.delegate_url = Uri(href)
+ except e as UriFormatException:
+ pass
+
+ if self.server_url is null:
+ raise ArgumentException("html did not contain openid.server link")
+
+ self.identity_url = uri
+ self.type_uris = (OPENID_1_0_TYPE,)
+ self.used_yadis = false
+
+ def UsesExtension(extension_uri as Uri):
+ return extension_uri in self.type_uris
+
+
+*/ \ No newline at end of file
diff --git a/source/Janrain.OpenId/Janrain.OpenId.csproj b/source/Janrain.OpenId/Janrain.OpenId.csproj
index 5faed4a..8b04015 100644
--- a/source/Janrain.OpenId/Janrain.OpenId.csproj
+++ b/source/Janrain.OpenId/Janrain.OpenId.csproj
@@ -40,6 +40,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Association.cs" />
+ <Compile Include="Consumer\AuthRequest.cs" />
+ <Compile Include="Consumer\ServiceEndpoint.cs" />
<Compile Include="CryptUtil.cs" />
<Compile Include="KVUtil.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -48,6 +50,8 @@
<Compile Include="Server\CheckIdRequest.cs" />
<Compile Include="Server\Codec.cs" />
<Compile Include="Server\IEncodable.cs" />
+ <Compile Include="Server\MalformedReturnUrl.cs" />
+ <Compile Include="Server\MalformedTrustRoot.cs" />
<Compile Include="Server\ProtocolException.cs" />
<Compile Include="Server\Request.cs" />
<Compile Include="Server\Response.cs" />
@@ -55,13 +59,16 @@
<Compile Include="Server\ServerSession.cs" />
<Compile Include="Server\Signatory.cs" />
<Compile Include="Server\TrustRoot.cs" />
+ <Compile Include="Server\UntrustedReturnUrl.cs" />
<Compile Include="Server\WebResponse.cs" />
<Compile Include="Store\IAssociationStore.cs" />
<Compile Include="Store\MemoryStore.cs" />
<Compile Include="Util.cs" />
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Consumer\" />
+ <Compile Include="Yadis\ServiceNode.cs" />
+ <Compile Include="Yadis\TypeNode.cs" />
+ <Compile Include="Yadis\UriNode.cs" />
+ <Compile Include="Yadis\Xrd.cs" />
+ <Compile Include="Yadis\XrdNode.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
diff --git a/source/Janrain.OpenId/Server/CheckIdRequest.cs b/source/Janrain.OpenId/Server/CheckIdRequest.cs
index b5984f9..f5cbad3 100644
--- a/source/Janrain.OpenId/Server/CheckIdRequest.cs
+++ b/source/Janrain.OpenId/Server/CheckIdRequest.cs
@@ -6,67 +6,6 @@ using System.Text;
namespace Janrain.OpenId.Server
{
- // TODO Move this out to it's own file
- public class UntrustedReturnUrl : ProtocolException
- {
-
- #region Private Members
-
- private Uri _return_to;
- private string _trust_root;
-
- #endregion
-
- #region Constructor(s)
-
- public UntrustedReturnUrl(NameValueCollection query, Uri return_to, string trust_root)
- : base(query, "return_to " + return_to.AbsoluteUri + " not under trust_root " + trust_root)
- {
- _return_to = return_to;
- _trust_root = trust_root;
- }
-
- #endregion
-
- }
-
- // TODO Move this out to it's own file
- public class MalformedReturnUrl : ProtocolException
- {
-
- #region Private Members
-
- private string _return_to;
-
- #endregion
-
- #region Constructor(s)
-
- public MalformedReturnUrl(NameValueCollection query, string return_to)
- : base(query, "")
- {
- _return_to = return_to;
- }
-
- #endregion
-
- }
-
- // TODO Move this out to it's own file
- public class MalformedTrustRoot : ProtocolException
- {
-
- #region Constructor(s)
-
- public MalformedTrustRoot(NameValueCollection query, string text)
- : base(query, text)
- {
- }
-
- #endregion
-
- }
-
public class CheckIdRequest : AssociatedRequest
{
@@ -244,7 +183,7 @@ namespace Janrain.OpenId.Server
q.Add("openid.assoc_handle", this.AssocHandle);
UriBuilder builder = new UriBuilder(server_url);
- Util.AppendQueryArgs(ref builder, q);
+ UriUtil.AppendQueryArgs(ref builder, q);
return new Uri(builder.ToString());
}
@@ -258,7 +197,7 @@ namespace Janrain.OpenId.Server
NameValueCollection args = new NameValueCollection();
args.Add("openid.mode", "cancel");
- Util.AppendQueryArgs(ref builder, args);
+ UriUtil.AppendQueryArgs(ref builder, args);
return new Uri(builder.ToString());
}
diff --git a/source/Janrain.OpenId/Server/MalformedReturnUrl.cs b/source/Janrain.OpenId/Server/MalformedReturnUrl.cs
new file mode 100644
index 0000000..f6e323c
--- /dev/null
+++ b/source/Janrain.OpenId/Server/MalformedReturnUrl.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace Janrain.OpenId.Server
+{
+ public class MalformedReturnUrl : ProtocolException
+ {
+
+ #region Private Members
+
+ private string _return_to;
+
+ #endregion
+
+ #region Constructor(s)
+
+ public MalformedReturnUrl(NameValueCollection query, string return_to)
+ : base(query, "")
+ {
+ _return_to = return_to;
+ }
+
+ #endregion
+
+ }
+}
diff --git a/source/Janrain.OpenId/Server/MalformedTrustRoot.cs b/source/Janrain.OpenId/Server/MalformedTrustRoot.cs
new file mode 100644
index 0000000..d567e3b
--- /dev/null
+++ b/source/Janrain.OpenId/Server/MalformedTrustRoot.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace Janrain.OpenId.Server
+{
+ public class MalformedTrustRoot : ProtocolException
+ {
+
+ #region Constructor(s)
+
+ public MalformedTrustRoot(NameValueCollection query, string text)
+ : base(query, text)
+ {
+ }
+
+ #endregion
+
+ }
+}
diff --git a/source/Janrain.OpenId/Server/ProtocolException.cs b/source/Janrain.OpenId/Server/ProtocolException.cs
index 79f1097..87d2332 100644
--- a/source/Janrain.OpenId/Server/ProtocolException.cs
+++ b/source/Janrain.OpenId/Server/ProtocolException.cs
@@ -79,7 +79,7 @@ namespace Janrain.OpenId.Server
q.Add("openid.error", this.Message);
UriBuilder builder = new UriBuilder(return_to);
- Util.AppendQueryArgs(ref builder, q);
+ UriUtil.AppendQueryArgs(ref builder, q);
return new Uri(builder.ToString());
}
diff --git a/source/Janrain.OpenId/Server/Response.cs b/source/Janrain.OpenId/Server/Response.cs
index f747fd3..f7371c0 100644
--- a/source/Janrain.OpenId/Server/Response.cs
+++ b/source/Janrain.OpenId/Server/Response.cs
@@ -143,7 +143,7 @@ namespace Janrain.OpenId.Server
CheckIdRequest checkidreq = (CheckIdRequest)this.Request;
UriBuilder builder = new UriBuilder(checkidreq.ReturnTo);
- Util.AppendQueryArgs(ref builder, nvc);
+ UriUtil.AppendQueryArgs(ref builder, nvc);
return new Uri(builder.ToString());
}
diff --git a/source/Janrain.OpenId/Server/UntrustedReturnUrl.cs b/source/Janrain.OpenId/Server/UntrustedReturnUrl.cs
new file mode 100644
index 0000000..77bf93e
--- /dev/null
+++ b/source/Janrain.OpenId/Server/UntrustedReturnUrl.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace Janrain.OpenId.Server
+{
+ public class UntrustedReturnUrl : ProtocolException
+ {
+
+ #region Private Members
+
+ private Uri _return_to;
+ private string _trust_root;
+
+ #endregion
+
+ #region Constructor(s)
+
+ public UntrustedReturnUrl(NameValueCollection query, Uri return_to, string trust_root)
+ : base(query, "return_to " + return_to.AbsoluteUri + " not under trust_root " + trust_root)
+ {
+ _return_to = return_to;
+ _trust_root = trust_root;
+ }
+
+ #endregion
+
+ }
+}
diff --git a/source/Janrain.OpenId/Util.cs b/source/Janrain.OpenId/Util.cs
index a1c3e4b..9bd05f7 100644
--- a/source/Janrain.OpenId/Util.cs
+++ b/source/Janrain.OpenId/Util.cs
@@ -6,7 +6,7 @@ using System.Web;
namespace Janrain.OpenId
{
- public static class Util
+ public static class UriUtil
{
#region NormalizeUri(string uriStr)
@@ -84,8 +84,12 @@ namespace Janrain.OpenId
#endregion
- #region InArray(string[] array, string valueToFind)
+ }
+ internal static class Util
+ {
+ #region InArray(string[] array, string valueToFind)
+
public static bool InArray(string[] array, string valueToFind)
{
foreach (string val in array)
@@ -94,8 +98,7 @@ namespace Janrain.OpenId
}
return false;
}
-
#endregion
-
}
+
}
diff --git a/source/Janrain.OpenId/Yadis/ServiceNode.cs b/source/Janrain.OpenId/Yadis/ServiceNode.cs
new file mode 100644
index 0000000..e56ffa0
--- /dev/null
+++ b/source/Janrain.OpenId/Yadis/ServiceNode.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+
+namespace Janrain.Yadis
+{
+ [Serializable]
+ public class ServiceNode : XrdNode, IComparable
+ {
+ public ServiceNode(XmlNode node, XmlDocument xmldoc, XmlNamespaceManager xmlns_manager)
+ : base(node, xmldoc, xmlns_manager)
+ {
+ }
+
+ public int CompareTo(object that)
+ {
+ if (that is ServiceNode)
+ {
+ return this.Priority.CompareTo(((ServiceNode)that).Priority);
+ }
+ return 0;
+ }
+
+ public TypeNode[] TypeNodes()
+ {
+ List<TypeNode> typeNodeList = new List<TypeNode>();
+ XmlNodeList typeNodes = base.node.SelectNodes("./xrd:Type", base.xmlnsManager);
+ foreach (XmlNode node in typeNodes)
+ {
+ typeNodeList.Add(new TypeNode(node, base.xmldoc, base.xmlnsManager));
+ }
+ return typeNodeList.ToArray();
+ }
+
+ public UriNode[] UriNodes()
+ {
+ List<UriNode> uriNodesList = new List<UriNode>();
+ XmlNodeList uriNodes = base.node.SelectNodes("./xrd:URI", base.xmlnsManager);
+ foreach (XmlNode node in uriNodes)
+ {
+ UriNode uriNode = new UriNode(this, node, base.xmldoc, base.xmlnsManager);
+ uriNodesList.Add(uriNode);
+ }
+ return uriNodesList.ToArray();
+ }
+
+ public int Priority
+ {
+ get
+ {
+ XmlAttribute namedItem = (XmlAttribute)base.node.Attributes.GetNamedItem("priority");
+ return Convert.ToInt32(namedItem.Value);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/source/Janrain.OpenId/Yadis/TypeNode.cs b/source/Janrain.OpenId/Yadis/TypeNode.cs
new file mode 100644
index 0000000..6cad460
--- /dev/null
+++ b/source/Janrain.OpenId/Yadis/TypeNode.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+
+namespace Janrain.Yadis
+{
+ [Serializable]
+ public class TypeNode : XrdNode
+ {
+ public TypeNode(XmlNode node, XmlDocument xmldoc, XmlNamespaceManager xmlnsManager)
+ : base(node, xmldoc, xmlnsManager)
+ {
+ }
+
+ public override string ToString()
+ {
+ return base.node.InnerXml;
+ }
+
+ public Uri Uri
+ {
+ get
+ {
+ try
+ {
+ return new Uri(this.ToString());
+ }
+ catch (UriFormatException)
+ {
+ return null;
+ }
+ }
+ }
+ }
+}
diff --git a/source/Janrain.OpenId/Yadis/UriNode.cs b/source/Janrain.OpenId/Yadis/UriNode.cs
new file mode 100644
index 0000000..b3df293
--- /dev/null
+++ b/source/Janrain.OpenId/Yadis/UriNode.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+
+namespace Janrain.Yadis
+{
+ [Serializable]
+ public class UriNode : XrdNode, IComparable
+ {
+ protected ServiceNode serviceNode;
+
+ public UriNode(XrdNode serviceNode, XmlNode node, XmlDocument xmldoc, XmlNamespaceManager xmlnsManager)
+ : base(node, xmldoc, xmlnsManager)
+ {
+ this.serviceNode = (ServiceNode)serviceNode;
+ }
+
+ public int CompareTo(object that)
+ {
+ if (that is UriNode)
+ {
+ UriNode node = (UriNode)that;
+ int num = this.serviceNode.CompareTo(node.serviceNode);
+ if (num == 0)
+ {
+ return this.Priority.CompareTo(node.Priority);
+ }
+ return num;
+ }
+ return 0;
+ }
+
+ public override string ToString()
+ {
+ return base.node.InnerXml;
+ }
+
+ // Properties
+ public int Priority
+ {
+ get
+ {
+ XmlAttribute namedItem = (XmlAttribute)base.node.Attributes.GetNamedItem("priority");
+ return Convert.ToInt32(namedItem.Value);
+ }
+ }
+
+ public ServiceNode ServiceNode
+ {
+ get
+ {
+ return this.serviceNode;
+ }
+ }
+
+ public Uri Uri
+ {
+ get
+ {
+ try
+ {
+ return new Uri(this.ToString());
+ }
+ catch (UriFormatException)
+ {
+ return null;
+ }
+ }
+ }
+ }
+}
diff --git a/source/Janrain.OpenId/Yadis/Xrd.cs b/source/Janrain.OpenId/Yadis/Xrd.cs
new file mode 100644
index 0000000..bbbfe01
--- /dev/null
+++ b/source/Janrain.OpenId/Yadis/Xrd.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+
+namespace Janrain.Yadis
+{
+ [Serializable]
+ public class Xrd
+ {
+ protected XmlDocument xmldoc = new XmlDocument();
+ protected XmlNamespaceManager xmlnsManager;
+ protected const string XRD_NAMESPACE = "xri://$xrd*($v*2.0)";
+ protected const string XRDS_NAMESPACE = "xri://$xrds";
+
+ public Xrd(string text)
+ {
+ this.xmldoc.LoadXml(text);
+ this.xmlnsManager = new XmlNamespaceManager(this.xmldoc.NameTable);
+ this.xmlnsManager.AddNamespace("xrds", "xri://$xrds");
+ this.xmlnsManager.AddNamespace("xrd", "xri://$xrd*($v*2.0)");
+ }
+
+ public ServiceNode[] ServiceNodes()
+ {
+ List<ServiceNode> serviceNodeList = new List<ServiceNode>();
+ string xpath = "/xrds:XRDS/xrd:XRD[last()]/xrd:Service";
+ XmlNodeList serviceNodes = this.xmldoc.SelectNodes(xpath, this.xmlnsManager);
+ foreach (XmlNode node in serviceNodes)
+ {
+ serviceNodeList.Add(new ServiceNode(node, this.xmldoc, this.xmlnsManager));
+ }
+ return serviceNodeList.ToArray();
+ }
+
+ public UriNode[] UriNodes()
+ {
+ List<UriNode> uriNodeList = new List<UriNode>();
+ ServiceNode[] serviceNodesArray = this.ServiceNodes();
+ foreach (ServiceNode serviceNode in serviceNodesArray)
+ {
+ UriNode[] nodes = serviceNode.UriNodes();
+ uriNodeList.AddRange(nodes);
+ }
+ uriNodeList.Sort();
+ return uriNodeList.ToArray();
+ }
+
+ public XmlDocument XmlDoc
+ {
+ get
+ {
+ return this.xmldoc;
+ }
+ }
+
+ public XmlNamespaceManager XmlNsManager
+ {
+ get
+ {
+ return this.xmlnsManager;
+ }
+ }
+ }
+}
diff --git a/source/Janrain.OpenId/Yadis/XrdNode.cs b/source/Janrain.OpenId/Yadis/XrdNode.cs
new file mode 100644
index 0000000..bff626b
--- /dev/null
+++ b/source/Janrain.OpenId/Yadis/XrdNode.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Xml;
+
+namespace Janrain.Yadis
+{
+ [Serializable]
+ public class XrdNode
+ {
+ protected XmlNode node;
+ protected XmlDocument xmldoc;
+ protected XmlNamespaceManager xmlnsManager;
+
+ public XrdNode(XmlNode node, XmlDocument xmldoc, XmlNamespaceManager xmlnsManager)
+ {
+ this.node = node;
+ this.xmldoc = xmldoc;
+ this.xmlnsManager = xmlnsManager;
+ }
+
+ public XmlNode Node
+ {
+ get
+ {
+ return this.node;
+ }
+ }
+
+ public XmlDocument XmlDoc
+ {
+ get
+ {
+ return this.xmldoc;
+ }
+ }
+
+ public XmlNamespaceManager XmlNsManager
+ {
+ get
+ {
+ return this.xmlnsManager;
+ }
+ }
+ }
+}