September 12, 2009 - 12:33 PM (GMT)
Category: Coldfusion,Notes,OpenID
Author: Charles
I was recently integrating OpenID into my SaaS Intranet offering over at CompositeWeb. I started working with the opensource project OpenID at riaforge. It worked great, but then I found the RPXnow site and thought it would provide a lot more flexibility in the future and provide for an easier to maintain interface.
I didn't find any information on how to implement it with coldfusion so I thought I would post what I figured out.
Keep in mind this is a simplified version of validation and using the PRXnow api to get data about the user. You need to signup for an account at RPXnow (which they do offer a free version of). You will also need to go to CFLib.org to download the jsondecode UDF so that you can parse the json data that the api returns. In the code below I have cfincluded the udf.
<cfinclude template="jsondecode.cfm">
<cfset token_url = "http://the url where your page is">
<cfset apiKey = "your api key">
<cfif isdefined('url.token')>
<!--- RPXnow returns a token that you can then use against their API to get the user info --->
<cfhttp method="post" url="https://rpxnow.com/api/v2/auth_info" >
<cfhttpparam type="formfield" name="apiKey" value="#apiKey#" />
<cfhttpparam type="formfield" name="token" value="#url.token#" />
</cfhttp>
<cfset retStruct = jsondecode(cfhttp.FileContent)>
<cfdump var="#retStruct#">
<cfif retStruct.stat eq 'ok'>
<h1>Logged In</h1>
<cfelse>
<h1>Not</h1>
</cfif>
</cfif>
<cfoutput>
<a class="rpxnow" onclick="return false;"
href="https://the url they give you.rpxnow.com/openid/v2/signin?token_url=#token_url#">Sign In</a>
</cfoutput>
<script src="https://rpxnow.com/openid/v2/widget" type="text/javascript"></script>
<script type="text/javascript">
RPXNOW.overlay = true;
RPXNOW.language_preference = 'en';
</script>
Once you run that, and you successfully login, it will dump out the data provided by the openid provider. RPXnow also has some great documentation on their site if you need to dig a little deeper.
Good luck!