All the functions, which can be put in a separate file and just included where needed


<!---------------------------------------------- >
<!--- code for mywebsite.com/func_oauth.cfm --->
<!---Generates the HMAC-SHA1 authentication code required by OAuth.--->
<cffunction name="HMAC_SHA1" returntype="binary" access="public" output="no">
<cfargument name="signKey" type="string" required="true" />
<cfargument name="signMessage" type="string" required="true" />
<cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") />
<cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") />
<cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") />
<cfset var mac = createObject("java","javax.crypto.Mac") />
<cfset key = key.init(jKey,"HmacSHA1") />
<cfset mac = mac.getInstance(key.getAlgorithm()) />
<cfset mac.init(key) />
<cfset mac.update(jMsg) />
<cfreturn mac.doFinal() />
</cffunction>

<!---Generates the OAuth "base string" from the parameters of your OAuth request.--->
<cffunction name="OauthBaseString" returntype="string" access="public" output="no">
<cfargument name="http_method" type="string" required="true">
<cfargument name="base_uri" type="string" required="true">
<cfargument name="parameters" type="struct" required="true">
<cfset oauth_signature_base_string = http_method & "&" & URLEncodedFormat_3986(base_uri) & "&">
<cfset keys_list = StructKeyList(parameters)>
<cfset keys_list_sorted = ListSort(keys_list,"textnocase")>
<cfset amp = "">
<cfloop list="#keys_list_sorted#" index="key">
<cfset oauth_signature_base_string = oauth_signature_base_string & URLEncodedFormat_3986(amp & LCase(key) & "=" & parameters[key])>
<cfset amp = "&">
</cfloop>
<cfreturn oauth_signature_base_string>
</cffunction>

<!---This is the engine of the OAuth car. Generates the OAuth request header and signature, submits to the provider (e.g., Twitter) and returns the response in a string.--->
<cffunction name="oauth_request" returntype="string" access="public" output="no">
<cfargument name="consumer_secret" type="string" required="yes">
<cfargument name="token_secret" type="string" required="yes">
<cfargument name="http_method" type="string" required="yes">
<cfargument name="request_url" type="string" required="yes">
<cfargument name="params" type="struct" required="yes">

<cfset params_backup = Duplicate(params)>
<cfset request_url_address = request_url>
<cfset request_url_query_string = "">
<cfset question_mark = Find("?",request_url,1)>
<cfif question_mark neq 0>
<cfset request_url_address = Left(request_url,question_mark-1)>
<cfset request_url_query_string = Right(request_url,(len(request_url)-question_mark))>
<cfset request_url_query_string = Replace(request_url_query_string, "&&", "PLACEHOLDER_AMPERSAND", "ALL")>
<cfset request_url_query_string = Replace(request_url_query_string, "==", "PLACEHOLDER_EQUALS", "ALL")>
<cfset params_list = ListChangeDelims(request_url_query_string,",","&,=")>
<cfloop from="1" to="#ListLen(params_list)#" index="index" step="2">
<cfset params[ListGetAt(params_list,index)] = ListGetAt(params_list,index+1)>
<cfset params[ListGetAt(params_list,index)] = Replace(params[ListGetAt(params_list,index)], "PLACEHOLDER_AMPERSAND", "&", "ALL")>
<cfset params[ListGetAt(params_list,index)] = Replace(params[ListGetAt(params_list,index)], "PLACEHOLDER_EQUALS", "=", "ALL")>
</cfloop>
</cfif>

<cfloop list="#StructKeyList(params)#" index="key">
<cfset params[key] = URLEncodedFormat_3986(params[key])>
</cfloop>

<cfset signature_base_string = OauthBaseString(http_method,request_url_address,params)>
<cfset composite_signing_key = consumer_secret & "&" & token_secret>
<cfset signature = ToBase64(HMAC_SHA1(composite_signing_key,signature_base_string))>
<cfset signature = URLEncodedFormat_3986(signature)>
<cfset oauth_header = "OAuth realm="""",">
<cfset comma = "">

<cfloop list="#StructKeyList(params_backup)#" index="key">
<cfset oauth_header = oauth_header & comma & key & "=""" & params[key] & """">
<cfset comma = ", ">
</cfloop>

<cfset oauth_header = oauth_header & ", oauth_signature=""" & signature & """">
<cfset myURL = "#request_url_address#?oauth_signature=#signature#">

<cfloop list="#StructKeyList(params)#" index="key">
<cfset myURL = "#myURL#&#key#=#params[key]#">
</cfloop>

<cfhttp method="post" url="#myURL#">
<cfhttpparam type="header" name="Authorization" value="#oauth_header#" encoded="no">
<cfloop list="#StructKeyList(params)#" index="key">
<cfif StructKeyExists(params_backup,key)>
<cfhttpparam type="formfield" name="#key#" value="#params[key]#" encoded="no">
</cfif>
</cfloop>
</cfhttp>
<cfif cfhttp.Statuscode neq "200 OK">
<h1>Failure!</h1>
<cfdump var="#variables#">
<cfabort>
</cfif>
<cfreturn cfhttp.FileContent>

</cffunction>

<!---Enhances ColdFusion's URLEncoded() function to produce strings compliant with RFC 3986.--->
<cffunction name="URLEncodedFormat_3986" returntype="string" access="public" output="no">
<cfargument name="url" type="string" required="true" />
<cfset rfc_3986_bad_chars = "%2D,%2E,%5F,%7E">
<cfset rfc_3986_good_chars = "-,.,_,~">
<cfset url = ReplaceList(URLEncodedFormat(url),rfc_3986_bad_chars,rfc_3986_good_chars)>
<cfreturn url />
</cffunction>
<!------------------- Done with func_oauth.cfm --------------------- >

Example code for getting the access token for one user.


<!---------------------------------------------- >
<!--- code for mywebsite.com/test_oauth.cfm --->
<!--- what you start with
API key: aaaaa
user key = bbbbb
oAuth Consumer Key: ccccc
oAuth Consumer Secret: ddddd
--->

<!--- what you end with
oauth_token_secret = eeeee
access_token = fffff
access_token_secret = ggggg
access_oauth_response = oauth_token=fffff&oauth_token_secret=ggggg
--->

<cfparam name="request_pass" type="any" default="1">
<cfinclude template="func_oauth.cfm">

<!--- ACTUAL PROGRAM --->
<!---At the end of this code, you should have the request token and request secret.--->

<cfif request_pass eq 0>
<cfset gmt_time_zone = "3">

<cfset http_method = "POST">
<cfset request_url = "http://eventful.com/oauth/request_token">
<cfset oauth_consumer_secret = "ddddd">

<cfset params = StructNew()>

<cfset params["oauth_callback"] = "http://www.mywebsite.com/test_oauth.cfm">
<cfset params["oauth_consumer_key"] = "ccccc">
<cfset params["oauth_nonce"] = DateFormat(Now(),'yymmdd') & TimeFormat (Now(),'hhmmssl')>
<cfset params["oauth_signature_method"] = "HMAC-SHA1">
<cfset params["oauth_timestamp"] = DateDiff("s", "January 1 1970 00:00", (Now()+(gmt_time_zone/24)))>
<cfset params["oauth_version"] = "1.0">

<cfset oauth_response = oauth_request(oauth_consumer_secret,"",http_method,request_url,params)>

<cfset oauth_token_start = Find("oauth_token=",oauth_response)+12>
<cfset oauth_token_end = Find("&",oauth_response,oauth_token_start)>
<cfset pass_1_token = Mid(oauth_response,oauth_token_start,(oauth_token_end-oauth_token_start))>

<cfset oauth_token_secret_start = Find("oauth_token_secret=",oauth_response)+19>
<cfset oauth_token_secret_end = Find("&",oauth_response,oauth_token_secret_start)>
<cfset CLIENT.pass_1_token_secret = Mid(oauth_response,oauth_token_secret_start,(oauth_token_secret_end-oauth_token_secret_start))> <!--- stored as client var (cookie) to access it on second passthrough --->

pass_1_token = <cfoutput>#pass_1_token#</cfoutput>
pass_1_token_secret = <cfoutput>#pass_1_token_secret#</cfoutput>


<!--- in browser:--->
<cfoutput><cflocation url="http://eventful.com/oauth/authorize?oauth_token=#pass_1_token#" addtoken="no"></cfoutput>

</cfif>

<!---receive: oauth_token=xxx&oauth_verifier=yyy--->


<!---At the end of this code, you should have the access token and token secret.--->

<cfif request_pass eq 1>
<cfset gmt_time_zone = "3">

<cfset http_method = "POST">
<cfset request_url = "http://eventful.com/oauth/access_token">
<cfset oauth_consumer_secret = "ddddd">
<cfset oauth_token_secret = "#CLIENT.pass_1_token_secret#">

<cfset params = StructNew()>

<cfset params["oauth_consumer_key"] = "ccccc">
<cfset params["oauth_nonce"] = DateFormat(Now(),'yymmdd') & TimeFormat (Now(),'hhmmssl')>
<cfset params["oauth_signature_method"] = "HMAC-SHA1">
<cfset params["oauth_timestamp"] = DateDiff("s", "January 1 1970 00:00", (Now()+(gmt_time_zone/24)))>
<cfset params["oauth_token"] = "#oauth_token#"> <!--- var in the url placed by Eventful--->
<cfset params["oauth_verifier"] = "#oauth_verifier#"> <!--- var in the url placed by Eventful--->
<cfset params["oauth_version"] = "1.0">


<cfset oauth_response = oauth_request(oauth_consumer_secret,oauth_token_secret,http_method,request_url,params)>
<br />pass_2_oauth_response = <cfoutput>#oauth_response#</cfoutput>

<cfset oauth_token_start = Find("oauth_token=",oauth_response)+12>
<cfset oauth_token_end = Find("&",oauth_response,oauth_token_start)>
<cfset token = Mid(oauth_response,oauth_token_start,(oauth_token_end-oauth_token_start))>

<cfset oauth_token_secret_start = Find("oauth_token_secret=",oauth_response)+19>
<cfset oauth_token_secret_end = Find("&",oauth_response,oauth_token_secret_start)>
<cfset token_secret = right(oauth_response,(len(oauth_response)-(oauth_token_secret_start-1)))>

<br />pass_2_token = <cfoutput>#token#</cfoutput>
<br />pass_2_token_secret = <cfoutput>#token_secret#</cfoutput>
<br />pass_2_oauth_response = <cfoutput>#oauth_response#</cfoutput>
</cfif>

<!---end request code--->
<!------------------- Done with test_oauth.cfm --------------------- >

Add Venue example with access token generated from above.



<!--- sample code for ongoing processing, eg, adding events and venues --->

<!--- once for script, not each request --->
<cfinclude template="func_oauth.cfm">
<cfset gmt_time_zone = "8"> <!--- I'm not sure this shouldn't be -8 but I'm not sure it matters, just used for oauth timestamp --->
<cfset oauth_consumer_secret = "ddddd">
<cfset oauth_token_secret = "eeeee">
<cfset app_key = "aaaaa">
<cfset user_key = "bbbbb">
<cfset oauth_consumer_key = "ccccc">
<cfset oauth_token = "fffff">


<!--- create new Eventful venue --->

<!--- start new oauth code for add venue --->

<cfset http_method = "POST">
<cfset request_url = "http://api.eventful.com/rest/venues/new">

<cfset params = StructNew()>

<cfset params["address"] = "#new_venue_addr#">
<cfset params["app_key"] = "#app_key#">
<cfset params["city"] = "#new_venue_city#">
<cfset params["country"] = "#new_venue_country#">
<cfset params["name"] = "#new_venue_name#">
<cfset params["oauth_consumer_key"] = "#oauth_consumer_key#">
<cfset params["oauth_nonce"] = DateFormat(Now(),'yymmdd') & TimeFormat (Now(),'hhmmssl')>
<cfset params["oauth_signature_method"] = "HMAC-SHA1">
<cfset params["oauth_timestamp"] = DateDiff("s", "January 1 1970 00:00", (Now()+(gmt_time_zone/24)))>
<cfset params["oauth_token"] = "#oauth_token#">
<cfset params["oauth_version"] = "1.0">
<cfset params["postal_code"] = "#new_venue_zip#">
<cfset params["region"] = "#new_venue_state#">
<cfset params["url"] = "#new_venue_URL#">
<cfset params["venue_type"] = "#new_venue_type#">

<cfset oauth_response = oauth_request(oauth_consumer_secret,oauth_token_secret,http_method,request_url,params)>

<cfset Eventful_venue_response = XmlParse(#oauth_response#)>

<cfif Eventful_venue_response.XmlRoot.XmlName is "error">
<br /><cfdump var=#Eventful_venue_response#>
<cfelse>
<!--- new Eventful venue processing --->
</cfif>