Guest User

Untitled

a guest
May 20th, 2011
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1.  
  2.  
  3. <cfset epochTimestamp2 = DateDiff("s", "January 1 1970 00:00", now()) />
  4.  
  5.  
  6. <!--- try %26 if & fails --->
  7. <cfset tempURL = tempURL & "http://social.yahooapis.com/v1/user/#response.xoauth_yahoo_guid#/contacts?">
  8. <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
  9. <cfset tempURL = tempURL & "&oauth_signature_method=HMAC-SHA1" />
  10. <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
  11. <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp2#" />
  12. <cfset tempURL = tempURL & "&oauth_token=#response.oauth_token#" />
  13. <cfset tempURL = tempURL & "&oauth_version=1.0" />
  14. <cfset tempURL = tempURL & "&xoauth_lang_pref=en-us" />
  15.  
  16.  
  17. <cfset signMessage = "GET&" & URLEncodedFormat(tempurl) />
  18. <cfdump var="#signMessage#">
  19.  
  20.  
  21. <cfset signkey = "#consumerSecret#%26#session.oauth_token_secret#" />
  22.  
  23. <cfset oauthsig = hmacEncrypt(signmessage,signkey) />
  24.  
  25. <cfdump var="#oauthsig#">
  26. <HR><HR>
  27.  
  28. <!---
  29. An uppercased HTTP method: GET, POST, etc.
  30. An ‘&’
  31. A url without any parameters (scheme://fqdn/path)
  32. An ‘&’
  33. 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.
  34.  
  35.  
  36. POST&https%3A%2F%2Fapi.login.yahoo.com%2Foauth%2Fv2%2Fget_request_token
  37. &oauth_consumer_key%3Ddj0yJmk9YmxIanRLOGQybWFCJmQ9WVdrOUxWbFBVMWRUTmpRbWNHbzlNQ1o1UFRFLSZzPWNvbnN1bWVyc2VjcmV0Jng9YTc-
  38. %26oauth_nonce%3DJsZywH
  39. %26oauth_signature_method%3DHMAC-SHA1
  40. %26oauth_timestamp%3D1221089876
  41. %26oauth_version%3D1.0
  42. %26xoauth_lang_pref%3Den-us
  43. --->
  44.  
  45.  
  46.  
  47.  
  48. <cfset tempURL = "http://social.yahooapis.com/v1/user/#response.xoauth_yahoo_guid#/contacts" /> <!--- ?format=json --->
  49. <!--- <cfset tempURL = tempURL & "realm=yahooapis.com" /> --->
  50. <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
  51. <cfset tempURL = tempURL & "&oauth_signature_method=HMAC-SHA1" />
  52. <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
  53. <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp2#" />
  54. <cfset tempURL = tempURL & "&oauth_token=#response.oauth_token#" />
  55. <cfset tempURL = tempURL & "&oauth_version=1.0" />
  56. <cfset tempURL = tempURL & "&oauth_signature=#oauthsig#" />
  57. <cfset tempURL = tempURL & "&xoauth_lang_pref=en-us#" />
  58.  
  59. <!---
  60.  
  61. <cfset tempURL = tempURL & "&oauth_signature=#consumerSecret#%26#session.oauth_token_secret#" />
  62. --->
  63. <cfdump var="#tempURL#">
  64. <cfhttp method="get" url="#tempURL#" result="getContacts" />
  65. <cfdump var="#getContacts#">
  66.  
  67.  
  68.  
  69.  
  70.  
  71. <cffunction name="hmacEncrypt" returntype="any" access="public" output="false">
  72. <cfargument name="signKey" type="string" required="true" />
  73. <cfargument name="signMessage" type="string" required="true" />
  74.  
  75. <cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") />
  76. <cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") />
  77.  
  78. <cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") />
  79. <cfset var mac = createObject("java","javax.crypto.Mac") />
  80.  
  81. <cfset key = key.init(jKey,"HmacSHA1") />
  82.  
  83. <cfset mac = mac.getInstance(key.getAlgorithm()) />
  84. <cfset mac.init(key) />
  85. <cfset mac.update(jMsg) />
  86.  
  87. <cfreturn toString(mac.doFinal()) />
  88. </cffunction>
  89.  
  90.  
  91. <cfscript>
  92. /**
  93. * Converts a URL query string to a structure.
  94. *
  95. * @param qs Query string to parse. Defaults to cgi.query_string. (Optional)
  96. * @return Returns a struct.
  97. * @author Malessa Brisbane ([email protected])
  98. * @version 1, April 11, 2006
  99. */
  100. function queryStringToStruct(qs) {
  101. //var to hold the final structure
  102. var struct = StructNew();
  103. //vars for use in the loop, so we don't have to evaluate lists and arrays more than once
  104. var i = 1;
  105. var pairi = "";
  106. var keyi = "";
  107. var valuei = "";
  108. var qsarray = "";
  109.  
  110.  
  111.  
  112. //put the query string into an array for easier looping
  113. qsarray = listToArray(qs, "&");
  114. //now, loop over the array and build the struct
  115. for (i = 1; i lte arrayLen(qsarray); i = i + 1){
  116. pairi = qsarray[i]; // current pair
  117. keyi = listFirst(pairi,"="); // current key
  118. valuei = urlDecode(listLast(pairi,"="));// current value
  119. // check if key already added to struct
  120. if (structKeyExists(struct,keyi)) struct[keyi] = listAppend(struct[keyi],valuei); // add value to list
  121. else structInsert(struct,keyi,valuei); // add new key/value pair
  122. }
  123. // return the struct
  124. return struct;
  125. }
  126. </cfscript>
Advertisement
Add Comment
Please, Sign In to add comment