1
votes

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#">
2
can you show us some code and provide proper documentation link to etsy api?Tushar Bhaware
What code have you used so far to attempt this?haxtbh
What is the result of #cfhttp.filecontent# - what are you getting back?Mark A Kruger

2 Answers

1
votes

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>
1
votes

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