Thursday, September 02, 2010

Janrian Engage coldfusion implementation

I've been thinking about ways to implement a new login system for a project I'm working on and decided to play around with openID and Janrain engage. Janrain supply code examples for various languages but not Coldfusion. As the project is CFM based I converted their php example, the sample code can be found below: Of course there are potentially other profile properties that may come back depending on the provider a user logs in with.

Here's the code (I've been trying without success to get SyntaxHighlighter working on my blog, but not managed it so far), so apologies for the poor formatting.

<cfset variables.rpxapikey="your-rpxkey-here"> 
<cfif isdefined('form.token')=""> 
        <cfset variables.token="form.token"> 
        <cfset variables.post_data="arraynew(2)"> 
        <cfset variables.post_data[1][1]="token"> 
        <cfset variables.post_data[1][2]="apikey"> 
        <cfset variables.post_data[1][3]="format"> 
        <cfset variables.post_data[2][1]="form.token"> 
        <cfset variables.post_data[2][2]="rpxApiKey"> 
        <cfset variables.post_data[2][3]="json"> 
        <cfhttp method="post" url="https://rpxnow.com/api/v2/auth_info"> 
                <cfhttpparam name="token" type="formfield" value="#form.token#"> 
                <cfhttpparam name="apiKey" type="formfield" value="#variables.rpxApiKey#"> 
                <cfhttpparam name="format" type="formfield" value="json"> 
        </cfhttpparam></cfhttpparam></cfhttpparam></cfhttp> 
         
        <cfset variables.auth_info="DeserializeJSON(cfhttp.fileContent)"> 
        <cfif eq="" ok"="" variables.auth_info['stat']=""> 
         
                Output Everything:
<cfdump var="#variables.auth_info#"> 
         
        <cfelse> 
                 
                <cfoutput>Not logged in, An error occured, 
#variables.auth_info['err']['msg']#, <a href="http://www.blogger.com/post-edit.g?blogID=35790578&postID=2472009727477842793#application.home#/ login">try again</a></cfoutput> 
        </cfelse></cfdump></cfif> 
<cfelse> 
        <cflocation addtoken="false" url="#application.home#/login"> 
</cflocation></cfelse></cfset></cfset></cfset></cfset></cfset></cfset></cfset></cfset></cfset></cfif>
</cfset>

No comments: