Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfset epochTimestamp2 = DateDiff("s", "January 1 1970 00:00", now()) />
- <!--- try %26 if & fails --->
- <cfset tempURL = tempURL & "http://social.yahooapis.com/v1/user/#response.xoauth_yahoo_guid#/contacts?">
- <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
- <cfset tempURL = tempURL & "&oauth_signature_method=HMAC-SHA1" />
- <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
- <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp2#" />
- <cfset tempURL = tempURL & "&oauth_token=#response.oauth_token#" />
- <cfset tempURL = tempURL & "&oauth_version=1.0" />
- <cfset tempURL = tempURL & "&xoauth_lang_pref=en-us" />
- <cfset signMessage = "GET&" & URLEncodedFormat(tempurl) />
- <cfdump var="#signMessage#">
- <cfset signkey = "#consumerSecret#%26#session.oauth_token_secret#" />
- <cfset oauthsig = hmacEncrypt(signmessage,signkey) />
- <cfdump var="#oauthsig#">
- <HR><HR>
- <!---
- An uppercased HTTP method: GET, POST, etc.
- An ‘&’
- A url without any parameters (scheme://fqdn/path)
- An ‘&’
- All the query parameters (combined for both the API call and those for oauth) encoded according to rfc 3986 AND sorted by key. DO NOT include the oauth_signature parameter in this step, because you are generating the oauth_signature.
- POST&https%3A%2F%2Fapi.login.yahoo.com%2Foauth%2Fv2%2Fget_request_token
- &oauth_consumer_key%3Ddj0yJmk9YmxIanRLOGQybWFCJmQ9WVdrOUxWbFBVMWRUTmpRbWNHbzlNQ1o1UFRFLSZzPWNvbnN1bWVyc2VjcmV0Jng9YTc-
- %26oauth_nonce%3DJsZywH
- %26oauth_signature_method%3DHMAC-SHA1
- %26oauth_timestamp%3D1221089876
- %26oauth_version%3D1.0
- %26xoauth_lang_pref%3Den-us
- --->
- <cfset tempURL = "http://social.yahooapis.com/v1/user/#response.xoauth_yahoo_guid#/contacts" /> <!--- ?format=json --->
- <!--- <cfset tempURL = tempURL & "realm=yahooapis.com" /> --->
- <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
- <cfset tempURL = tempURL & "&oauth_signature_method=HMAC-SHA1" />
- <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
- <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp2#" />
- <cfset tempURL = tempURL & "&oauth_token=#response.oauth_token#" />
- <cfset tempURL = tempURL & "&oauth_version=1.0" />
- <cfset tempURL = tempURL & "&oauth_signature=#oauthsig#" />
- <cfset tempURL = tempURL & "&xoauth_lang_pref=en-us#" />
- <!---
- <cfset tempURL = tempURL & "&oauth_signature=#consumerSecret#%26#session.oauth_token_secret#" />
- --->
- <cfdump var="#tempURL#">
- <cfhttp method="get" url="#tempURL#" result="getContacts" />
- <cfdump var="#getContacts#">
- <cffunction name="hmacEncrypt" returntype="any" access="public" output="false">
- <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 toString(mac.doFinal()) />
- </cffunction>
- <cfscript>
- /**
- * Converts a URL query string to a structure.
- *
- * @param qs Query string to parse. Defaults to cgi.query_string. (Optional)
- * @return Returns a struct.
- * @author Malessa Brisbane ([email protected])
- * @version 1, April 11, 2006
- */
- function queryStringToStruct(qs) {
- //var to hold the final structure
- var struct = StructNew();
- //vars for use in the loop, so we don't have to evaluate lists and arrays more than once
- var i = 1;
- var pairi = "";
- var keyi = "";
- var valuei = "";
- var qsarray = "";
- //put the query string into an array for easier looping
- qsarray = listToArray(qs, "&");
- //now, loop over the array and build the struct
- for (i = 1; i lte arrayLen(qsarray); i = i + 1){
- pairi = qsarray[i]; // current pair
- keyi = listFirst(pairi,"="); // current key
- valuei = urlDecode(listLast(pairi,"="));// current value
- // check if key already added to struct
- if (structKeyExists(struct,keyi)) struct[keyi] = listAppend(struct[keyi],valuei); // add value to list
- else structInsert(struct,keyi,valuei); // add new key/value pair
- }
- // return the struct
- return struct;
- }
- </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment