Guest User

Untitled

a guest
May 20th, 2011
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <cfset consumerKey = "dj0yJmk9SFNyUFZmSTJ0NUl3JmQ9WVdrOWRsVjBjV0pRTldjbWNHbzlOVGsyTWpBeU5qWXkmcz1jb25zdW1lcnNlY3JldCZ4PWFm" />
  2. <cfset consumerSecret = "2d270eb83117b19223d76ecbf209f1130ad8fce8" />
  3. <cfset epochTimestamp = DateDiff("s", "January 1 1970 00:00", now()) />
  4. <cfset randomString = replace(createUUID(),"-","","all") />
  5.  
  6.  
  7. <cfoutput>#consumerSecret#&#session.oauth_token_secret#%26</cfoutput>
  8.  
  9. <cfset tempURL = "https://api.login.yahoo.com/oauth/v2/get_token?" />
  10. <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
  11. <cfset tempURL = tempURL & "&oauth_signature_method=PLAINTEXT" />
  12. <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
  13. <cfset tempURL = tempURL & "&oauth_signature=#consumerSecret#%26#session.oauth_token_secret#" />
  14. <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp#" />
  15. <cfset tempURL = tempURL & "&oauth_verifier=#url.oauth_verifier#" />
  16. <cfset tempURL = tempURL & "&oauth_version=1.0" />
  17. <cfset tempURL = tempURL & "&oauth_token=#url.oauth_token#" />
  18.  
  19. <cfhttp method="get" url="#tempURL#" result="accessTokenRequest" />
  20. <cfdump var="#accessTokenRequest#">
  21.  
  22. <cfoutput>#accessTokenRequest.filecontent#</cfoutput>
  23. <cfset response = queryStringToStruct(accessTokenRequest.filecontent) />
  24. <cfdump var="#response#" label="response">
  25. <hr>
  26.  
  27.  
  28.  
  29. <cfset epochTimestamp2 = DateDiff("s", "January 1 1970 00:00", now()) />
  30.  
  31.  
  32. <!--- try %26 if & fails --->
  33. <cfset tempURL = tempURL & "http://social.yahooapis.com/v1/user/#response.xoauth_yahoo_guid#/contacts?">
  34. <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
  35. <cfset tempURL = tempURL & "&oauth_signature_method=HMAC-SHA1" />
  36. <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
  37. <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp2#" />
  38. <cfset tempURL = tempURL & "&oauth_token=#response.oauth_token#" />
  39. <cfset tempURL = tempURL & "&oauth_version=1.0" />
  40. <cfset tempURL = tempURL & "&xoauth_lang_pref=en-us" />
  41.  
  42.  
  43. <cfset signMessage = "GET&" & URLEncodedFormat(tempurl) />
  44. <cfdump var="#signMessage#">
  45.  
  46.  
  47. <cfset signkey = "#consumerSecret#%26#session.oauth_token_secret#" />
  48.  
  49. <cfset oauthsig = hmacEncrypt(signkey,signmessage) />
  50.  
  51. <cfdump var="#oauthsig#">
  52. <HR><HR>
  53.  
  54. <!---
  55. An uppercased HTTP method: GET, POST, etc.
  56. An ‘&’
  57. A url without any parameters (scheme://fqdn/path)
  58. An ‘&’
  59. 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.
  60.  
  61.  
  62. POST&https%3A%2F%2Fapi.login.yahoo.com%2Foauth%2Fv2%2Fget_request_token
  63. &oauth_consumer_key%3Ddj0yJmk9YmxIanRLOGQybWFCJmQ9WVdrOUxWbFBVMWRUTmpRbWNHbzlNQ1o1UFRFLSZzPWNvbnN1bWVyc2VjcmV0Jng9YTc-
  64. %26oauth_nonce%3DJsZywH
  65. %26oauth_signature_method%3DHMAC-SHA1
  66. %26oauth_timestamp%3D1221089876
  67. %26oauth_version%3D1.0
  68. %26xoauth_lang_pref%3Den-us
  69. --->
  70.  
  71.  
  72.  
  73.  
  74. <cfset tempURL = "http://social.yahooapis.com/v1/user/#response.xoauth_yahoo_guid#/contacts" /> <!--- ?format=json --->
  75. <!--- <cfset tempURL = tempURL & "realm=yahooapis.com" /> --->
  76. <cfset tempURL = tempURL & "oauth_consumer_key=#consumerKey#" />
  77. <cfset tempURL = tempURL & "&oauth_signature_method=HMAC-SHA1" />
  78. <cfset tempURL = tempURL & "&oauth_nonce=#randomString#" />
  79. <cfset tempURL = tempURL & "&oauth_timestamp=#epochTimestamp2#" />
  80. <cfset tempURL = tempURL & "&oauth_token=#response.oauth_token#" />
  81. <cfset tempURL = tempURL & "&oauth_version=1.0" />
  82. <cfset tempURL = tempURL & "&oauth_signature=#oauthsig#" />
  83. <cfset tempURL = tempURL & "&xoauth_lang_pref=en-us" />
  84.  
  85.  
  86.  
  87.  
  88. <cfset tempURL = tempURL & "&oauth_signature=#consumerSecret#%26#session.oauth_token_secret#" />
  89.  
  90. <cfdump var="#tempURL#">
  91. <cfhttp method="get" url="#tempURL#" result="getContacts" />
  92. <cfdump var="#getContacts#">
  93.  
  94.  
  95.  
  96.  
  97. <cffunction name="hmacEncrypt" returntype="string" access="public">
  98. <cfargument name="signKey" type="string" required="true">
  99. <cfargument name="signMessage" type="string" required="true">
  100. <cfargument name="sFormat" type="string" required="false" default="iso-8859-1">
  101.  
  102. <cfset var jMsg = JavaCast("string", arguments.signMessage).getBytes(arguments.sFormat)>
  103. <cfset var jKey = JavaCast("string", arguments.signKey).getBytes(arguments.sFormat)>
  104.  
  105. <cfset var key = createObject("java", "javax.crypto.spec.SecretKeySpec")>
  106. <cfset var mac = createObject("java", "javax.crypto.Mac")>
  107.  
  108. <cfset key = key.init(jKey,"HmacSHA1")>
  109.  
  110. <cfset mac = mac.getInstance(key.getAlgorithm())>
  111. <cfset mac.init(key)>
  112. <cfset mac.update(jMsg)>
  113.  
  114. <cfreturn ToBase64(mac.doFinal())>
  115. </cffunction>
Advertisement
Add Comment
Please, Sign In to add comment