1

trying to request_login with ETSY api but nothing seems working ....

https://openapi.etsy.com/v2/oauth/request_token?oauth_consumer_key=a93ays32uckifw3k0lrsfy2n&oauth_nonce=82asXUrVrwV&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1416562333&oauth_version=1.0&oauth_signature=mBhVKblbSBes1f3AkvaJmjJSJ24=

oauth_consumer_key = a93ays32uckifw3k0lrsfy2n
oauth_nonce = 82asXUrVrwV
oauth_signature_method = HMAC-SHA1
oauth_timestamp = 1416562333
oauth_version = 1.0
oauth_signature = mBhVKblbSBes1f3AkvaJmjJSJ24=

please suggest how to proceed

i tried below code

<cfset tc = CreateObject("java", "java.util.Date").getTime()>
<cfset otimeStamp = Int(tc / 1000)>

<cfset iMin = 0>
<cfset iMax = CreateObject("java","java.lang.Integer").MAX_VALUE>
<cfset sToEncode = otimeStamp & RandRange(iMin, iMax)>
<cfset onounce =  Hash(sToEncode, "SHA")/>

<cffunction name="hmacEncrypt" returntype="binary" 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 mac.doFinal() />
</cffunction>

<cfset result = hmacEncrypt("a93ays32uckifw3k0lrsfy2n", "GET&https%3A%2F%2Fopenapi.etsy.com%2Fv2%2Foauth%2Frequest_token&oauth_consumer_key%3Da93ays32uckifw3k0lrsfy2n%26oauth_nonce%3D#onounce#%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#otimeStamp#%26oauth_version%3D1.0")>
<cfset osign = toString(tobase64(result))>

<cfhttp url="https://openapi.etsy.com/v2/oauth/request_token?oauth_consumer_key=a93ays32uckifw3k0lrsfy2n&oauth_nonce=#onounce#&oauth_signature_method=HMAC-SHA1&oauth_timestamp=#otimeStamp#&oauth_version=1.0&oauth_signature=#osign#">
        <cfhttpparam type="header" name="shop_id" value="cfdevshop">
        <cfhttpparam type="header" name="GData-Version" value="3">
</cfhttp>
<cfdump var="#cfhttp#">
Rikhi Sahu
  • 655
  • 1
  • 7
  • 19

2 Answers2

1

Your problem lies with timestamp. You are passing incorrect timestamp. You should pass timestamp value in seconds. You can calculate timestamp as follows:

<cfset dateObj = now() />
<cfset timestamp = dateObj.getTime() />
<cfset timestampInSeconds = timestamp/1000 />
<cfdump var="#timestampInSeconds#"><cfabort>

Timestamp should be +/- 5 minutes of your systems current timestamp.
I have used the all the parameters you have provided here in my code as follows:

<cfhttp url="https://openapi.etsy.com/v2/oauth/request_token">
    <cfhttpparam type="header" name="GData-Version" value="3">
    <cfhttpparam type="url" name="oauth_signature" value="mBhVKblbSBes1f3AkvaJmjJSJ24=" >
    <cfhttpparam type="url" name="oauth_version" value="1.0" >
    <cfhttpparam type="url" name="oauth_timestamp" value="#timestampInSeconds#" >
    <cfhttpparam type="url" name="oauth_signature_method" value="HMAC-SHA1" >
    <cfhttpparam type="url" name="oauth_nonce" value="8225XUrVrwV" >
    <cfhttpparam type="url" name="oauth_consumer_key" value="a93ays32uckifw3k0lrsfy2n" >
</cfhttp>
<cfdump var="#cfhttp#"><cfabort>

I guess you have provided dummy values (which is a good thing). You can see in the screenshot that i am getting different error (invalid oauth signature error). If you provide correct values, i think you are good to go.
enter image description here

The getTime() method is a java method of Date class. You can see how it works:

<cfset dateObj = createObject("java","java.util.Date") />
<cfset timeStamp = dateObj.getTime() />
<cfdump var="#timeStamp#"><cfabort>
Tushar Bhaware
  • 2,525
  • 1
  • 16
  • 29
  • hi tushar, please see i updated the code, i found some code to generate Time_stamp, oauth_nounce and oauth_signature, used in updated code, but still i am getting error "oauth_problem=signature_invalid". please suggest something – Rikhi Sahu Nov 24 '14 at 14:56
1

Done Etsy Oauth Authentication successfully using this package http://oauthconsumer.riaforge.org/

Rikhi Sahu
  • 655
  • 1
  • 7
  • 19
  • I was wondering if you could post any sample code of making, and completing the request and calling back your application with the auth-token. I followed a little to what you were doing above, but I am stuck with etsy not turning me back to my website with the final token. – steve Dec 01 '14 at 16:51
  • hi steve, there has been lot of changes in above code but as you want to be redirected in your website you will have to add another parameter oauth_callback with value(url) where you want to be redirected. – Rikhi Sahu Dec 05 '14 at 09:44
  • hi thanks. I ended up finding a twillio example ben nadel posted on his blog. I spend a few hours tearing it down and learning from it and was able to create a simple interface for etsy oauth and to start pulling feeds. – steve Dec 05 '14 at 19:55
  • 1
    @steve I know this thread is close to two years old. However, is there any chance you still have the simple etsy oauth code you did? I'm pulling my hair out getting Etsy OAuth to work on CF – charlestang Sep 28 '16 at 08:38