Guest User

Untitled

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