Providing your OpenID in ColdFusion, part 1: MachBlog

For some time now, I've been using my OpenID when entering comments on other people's blogs.  For those unfamiliar with OpenID, think of it as an easy way to establish the *identity* (authentication, or AuthN) of a commenter (or other user of your site).  More details at WikiPedia, and at OpenIdEnabled.

There are already a number of ColdFusion-based OpenID consumers and servers (though none seem to be leveraging existing Java OpenID code) -- but for the first step, you don't even need to involve ColdFusion at all.  For future steps (including setting up your own OpenID server), take a look at Dmitry Yakhnov's ColdFusion OpenID consumer and server (on RIA Forge), and the CFOpenID library from IndianKey.  There are full-featured Java libraries as well, such the the OpenID4Java library from Sxip. 

For now, though, we're only looking at how to provide a link to your OpenID identity using your blog (or other web presence), especially when using MachBlog.

The first step towards using OpenID is to create your OpenID identity.  In my case, I chose to use MyOpenID.com -- creating an account there (or at the identity provider of your choice) is essential for now (for advanced uses, you may set up your own authN server).  Providing a few basic details about myself and verifying my email address was all it took to create that account; the next step is to point to that account from a URL under your control

In my case, I chose my main blog site, tracylogan.com, which, at the time, was running my own blog software.  I added the two link tags as required, which define my chosen OpenID  provider, and the related OpenID delegate (public account details):

<link rel="openid.server" href="http://www.myopenid.com/server" />

<link rel="openid.delegate" href="http://logantracyo.myopenid.com/" />

By placing these link tags inside the <head> tag of my blog, I've provided an easy reference to my OpenID -- here's how I use that:

When I start to enter a comment on an OpenID-enabled block, I simply enter my OpenID URL (tracylogan.com) in the appropriate OpenID login field.  When I submit that form, the blog software requests my OpenID details, by redirecting me to my OpenID provider (as specified in the link tag above).  I see my OpenID provider, verify the URL, and log in with my password, along with a choice of what info to provide (usually just Full Name), and how long I want that to last (usually "this time only").

Assuming I provide the correct password, I'm redirected back to the blog, with my authentication information filled in.  Quick, easy, kinda fun, even!

After switching to MachBlog, though, I realized that my OpenID was gone (because I'd installed MachBlog at the site root, rather than in /machblog/ as is the norm).  Here's how I worked around that for now, while I'm writing code for full support  -- by adding the following lines to each Skin in the /machblog/skins folder (in Head section of the mainTemplate.cfm file, following line 16, typically):

<!--- include required links for OpenID Authentication on the home page, if desired --->
<cfif event.getArg("mainEvent") EQ getProperty("defaultEvent") AND getProperty('useOpenId')>

<link rel="openid.server" href="#getProperty('openIdServer')#" />
<link rel="openid.delegate" href="#getProperty('openIdDelegate')#" />

</cfif>

The OpenID links are only needed on the Default event, since that's all the OpenID client code will look for; it might actually make more sense to include those with each page, rather than using that conditional logic to exclude it elsewhere.  This is a first-stab, not a fully-recommended best practice!

The other step is to provide the referenced values in the config file (/machblog/config/mach-ii.xml.cfm, added after line 60, though anywhere in the Properties section will work):

<property name="useOpenId" value="true" />
<property name="openIdServer" value="http://www.myopenid.com/server" />
<property name="openIdDelegate" value="http://logantracyo.myopenid.com/" />

Of course, you'll want to replace at least the OpenIdDelegate with your own value (the OpenIdServer too, if you use someone other than MyOpenID.com)

Next up, I'll be working on adding OpenID authentication to the MachBlog comment page; if it goes well, I'll post the my ideas here.

0 Comments  |  ColdFusion, Mach-II, MetaBlog, Standards, The Web  | 
Posted 4/29/07 @ 2:10 PM by Tracy Logan