[9/28/07: Update: this control is now being hosted as part of the dotnetopenid project on Google Code]
OpenID is gaining ground, and with good reason. A cross-platform, cross-browser single Internet sign-on using a distributed network is very appealing. I’ll assume though that you already know what OpenID is and why it is a good choice for your web site. This post is about how to add support for OpenID to your web site very easily.
Most of the ease is attributable to the work of Grant Monroe (I believe) due to his work on the .NET implementation of OpenID. While his library seems to be functional, it leaves some to be desired when it comes to actually using it on your site. The steps he uses includes adding several lines to your Web.config file, adding a special .ashx handler class to your web project, and grabbing any request ending in login.aspx regardless of whether and which login page it is on your site.
I was able to leverage his library (written in Boo) with a C# library of my own to put a nice custom web control frontend on his OpenID implementation. Now, aside from adding the library to your web site’s Bin directory, all you have to do is add these two lines to your login page:
<%@ Register Assembly="NerdBank.Tools" Namespace="NerdBank.Tools.WebControls" TagPrefix="nb" %> <nb:OpenIdLogin ID="openIdLogin" runat="server" />
Not bad, eh? All you need before you add these lines is to drop in a compiled version of NerdBank.Tools.dll and its dependencies. You can download a drop, or download the source using Subversion. Both Janrain.dll and NerdBank.Tools.dll are licensed under the LGPL.
If you try this and find you want more control over the appearance than what the OpenIdLogin control offers, use the OpenIdTextBox control, which provides a barebones but fully functional control that does the same thing so you have more control over the UI.
Being that Janrain.dll (where OpenID is implemented) is written in Boo, with which I am not too familiar, I added my custom web control to my own existing C# tools library. Ideally Janrain’s author can take my code and rewrite it in Boo so that it can be all in one assembly for convenience, but I don’t see two assemblies as a big deal in the meantime. In order for my strong-named NerdBank.Tools assembly to reference Janrain.dll, I had to recompile Janrain.dll with a strong name. Other than that it’s the original assembly as I downloaded it from its original site.
The Janrain implementation does not provide (as far as I can tell) for requesting user details during the login process, as the OpenID specification allows for. I also use Janrain’s Ruby implementation of OpenID, which does provide this behavior, so I’m going to investigate this more and either contribute to his project or figure out how to use the feature and build it into my OpenIdLogin control so you can just set properties and they are delivered to you in the OpenIdLogin.OnLoggedIn event. I’ll report via another post on this blog on my progress.