ColdFusion与QuickBooks - 应用程序令牌和密钥

时间:2014-04-17 20:28:26

标签: api oauth coldfusion quickbooks quickbooks-online

我们目前有一个使用旧版QuickBooks SDK的应用程序。

我们被告知,5月15日将是我们实施工作的最后一天。有关此事的官方公告可在此处查看:

https://developer.intuit.com/blog/2013/12/19/2014-roadmap-and-migration-dates-for-existing-developers

https://developer.intuit.com/blog/2013/12/20/migration-details-quickbooks-online-sdk-to-quickbooks-online-rest-api-v3

我们目前正在尝试使用oauth(http://oauth.riaforge.org)...

任何例子或起点都不错。

我们尝试转换Twitter oauth示例,但它没有成功......

QuickBooks文档很好,但对ColdFusion并不深入。

示例代码:

<!--- set up the parameters --->
<cfset sConsumerKey = "xxxx"> <!--- the consumer key you got from google when registering you app  --->
<cfset sConsumerSecret = "xxxx"> <!--- the consumer secret you got from google --->
<cfset sTokenEndpoint = "https://oauth.intuit.com/oauth/v1/get_request_token"> <!--- Access Token URL --->
<cfset sAuthorizationEndpoint = "https://appcenter.intuit.com/Connect/Begin"> <!--- Authorize URL --->
<cfset sCallbackURL = "www.myurl.com"> <!--- where google will redirect to after the user enters their details --->
<cfset sClientToken = ""> <!--- returned after an access token call --->
<cfset sClientTokenSecret = ""> <!--- returned after an access token call --->


<!--- set up the required objects including signature method--->
<cfset oReqSigMethodSHA = CreateObject("component", "oauth.oauthsignaturemethod_hmac_sha1")>
<cfset oToken = CreateObject("component", "oauth.oauthtoken").createEmptyToken()>
<cfset oConsumer = CreateObject("component", "oauth.oauthconsumer").init(sKey = sConsumerKey, sSecret = sConsumerSecret)>


<cfset oReq = CreateObject("component", "oauth.oauthrequest").fromConsumerAndToken(
    oConsumer = oConsumer,
    oToken = oToken,
    sHttpMethod = "GET",
    sHttpURL = sTokenEndpoint)>
<cfset oReq.signRequest(
    oSignatureMethod = oReqSigMethodSHA,
    oConsumer = oConsumer,
    oToken = oToken)>

<cfhttp url="#oREQ.getString()#&oauth_callback=#sCallbackURL#" method="get" result="tokenResponse"/>

<!--- grab the token and secret from the response if its there--->
<cfif findNoCase("oauth_token",tokenresponse.filecontent)>
    <cfset sClientToken = listlast(listfirst(tokenResponse.filecontent,"&"),"=")>
    <cfset sClientTokenSecret = listlast(listlast(tokenResponse.filecontent,"&"),"=")>

    <!--- you can add some additional parameters to the callback --->
    <cfset sCallbackURL = sCallbackURL & "?" &
        "key=" & sConsumerKey &
        "&" & "secret=" & sConsumerSecret &
        "&" & "token=" & sClientToken &
        "&" & "token_secret=" & sClientTokenSecret &
        "&" & "endpoint=" & URLEncodedFormat(sAuthorizationEndpoint)>

    <cfoutput>#tokenResponse.filecontent#</cfoutput>
<cfelse>
    <cfoutput>#tokenResponse.filecontent#</cfoutput>
</cfif>

以下是我们遇到的错误:

oauth_problem=parameter_absent&oauth_parameters_absent=oauth_callback

更新的新错误 - 修正了上述问题。

oauth_problem=signature_invalid

2 个答案:

答案 0 :(得分:1)

问题是您必须在签名之前将oauth_callback参数添加到请求对象。试试这个:

<!--- set up the parameters --->
<cfset sConsumerKey = "xxxx"> <!--- the consumer key you got from google when registering you app  --->
<cfset sConsumerSecret = "xxxx"> <!--- the consumer secret you got from google --->
<cfset sTokenEndpoint = "https://oauth.intuit.com/oauth/v1/get_request_token"> <!--- Access Token URL --->
<cfset sAuthorizationEndpoint = "https://appcenter.intuit.com/Connect/Begin"> <!--- Authorize URL --->
<cfset sCallbackURL = "www.myurl.com"> <!--- where google will redirect to after the user enters their details --->
<cfset sClientToken = ""> <!--- returned after an access token call --->
<cfset sClientTokenSecret = ""> <!--- returned after an access token call --->


<!--- set up the required objects including signature method--->
<cfset oReqSigMethodSHA = CreateObject("component", "oauth.oauthsignaturemethod_hmac_sha1")>
<cfset oToken = CreateObject("component", "oauth.oauthtoken").createEmptyToken()>
<cfset oConsumer = CreateObject("component", "oauth.oauthconsumer").init(sKey = sConsumerKey, sSecret = sConsumerSecret)>


<cfset oReq = CreateObject("component", "oauth.oauthrequest").fromConsumerAndToken(
    oConsumer = oConsumer,
    oToken = oToken,
    sHttpMethod = "GET",
    sHttpURL = sTokenEndpoint)>
<!--- Add the parameter before you sign the request --->
<cfset oReq.setParameter('oauth_callback', sCallbackURL)>
<cfset oReq.signRequest(
    oSignatureMethod = oReqSigMethodSHA,
    oConsumer = oConsumer,
    oToken = oToken)>

<!--- Now just send the request using oREQ.getString() --->
<cfhttp url="#oREQ.getString()#" method="get" result="tokenResponse"/>

<!--- grab the token and secret from the response if its there--->
<cfif findNoCase("oauth_token",tokenresponse.filecontent)>
    <cfset sClientToken = listlast(listfirst(tokenResponse.filecontent,"&"),"=")>
    <cfset sClientTokenSecret = listlast(listlast(tokenResponse.filecontent,"&"),"=")>

    <!--- you can add some additional parameters to the callback --->
    <cfset sCallbackURL = sCallbackURL & "?" &
        "key=" & sConsumerKey &
        "&" & "secret=" & sConsumerSecret &
        "&" & "token=" & sClientToken &
        "&" & "token_secret=" & sClientTokenSecret &
        "&" & "endpoint=" & URLEncodedFormat(sAuthorizationEndpoint)>

    <cfoutput>#tokenResponse.filecontent#</cfoutput>
<cfelse>
    <cfoutput>#tokenResponse.filecontent#</cfoutput>
</cfif>

答案 1 :(得分:0)

我自己没有尝试过,但CF11显然已经在oauth上做了很多工作,发布日期是5月15日之前,如果我正确地记得Ray。值得一看?

https://wikidocs.adobe.com/wiki/display/coldfusionen/cfoauth