Intuit API OAuth ApplicationAuthenticationFailed;错误码= 003200

时间:2016-12-01 14:26:41

标签: api oauth coldfusion quickbooks-online intuit

我正在使用this library for OAuth v1.0连接到QuickBooks Online API。我成功地能够使用三脚认证并获得访问令牌。我也能够毫无问题地连接到大多数端点。但是,我在使用URL参数连接到端点时遇到问题。

例如,此网址返回时没有问题:

https://sandbox-quickbooks.api.intuit.com/v3/company/123145723805019/customer/8

但是,此URL返回SignatureBaseString:错误401 unAuthorized

//sandbox-quickbooks.api.intuit.com/v3/company/123145723805019/query?query=select * from customer

我是否误解了如何在OAuth中使用URL参数访问端点?任何帮助或见解将不胜感激。

工作代码:

<cfset oAuthRequest = new com.brianflove.oauth.Request()>
<cfset oAuthConsumer = new com.brianflove.oauth.Consumer()>
<cfset oauthConsumer.setSecret(CONSUMER_SECRET)>
<cfset oauthConsumer.setKey(CONSUMER_KEY)>
<cfset oAuthRequest.setMethod("GET")>
<cfset oAuthRequest.setUrl("https://sandbox-quickbooks.api.intuit.com/v3/company/123145723805019/customer/" & randrange(1,8))>
<cfset oAuthRequest.setConsumer(oAuthConsumer)>
<cfset oAuthRequest.setToken(session.token)>

<!---use HMAC-SHA1 signature method--->
<cfset signatureMethod = new com.brianflove.oauth.methods.HmacSha1SignatureMethod()>

<!---sign request--->
<cfset oAuthRequest.signWithSignatureMethod(signatureMethod=signatureMethod)>


<!---POST using request URL--->
<cfset httpRequest = new Http()>
<cfset httpRequest.setUrl(oAuthRequest.getUrl())>
<cfset httpRequest.setMethod(oAuthRequest.getMethod())>
<cfset httpRequest.addParam(type="header", name="Authorization", value=oAuthRequest.toHeader())>
<cfset httpRequest.addParam(type="header", name="Accept", value="application/json") />
<cfset httpRequest.setCharset("utf-8")>
<cfset httpResult = httpRequest.send().getPrefix()>

<cfdump var="#httpResult.filecontent#">

不工作代码:

<cfset oAuthRequest = new com.brianflove.oauth.Request()>
<cfset oAuthConsumer = new com.brianflove.oauth.Consumer()>
<cfset oauthConsumer.setSecret(CONSUMER_SECRET)>
<cfset oauthConsumer.setKey(CONSUMER_KEY)>
<cfset oAuthRequest.setMethod("GET")>
<cfset oAuthRequest.setUrl("https://sandbox-quickbooks.api.intuit.com/v3/company/123145723805019/query?query=select * from customer") />
<cfset oAuthRequest.setConsumer(oAuthConsumer)>
<cfset oAuthRequest.setToken(session.token)>

<!---use HMAC-SHA1 signature method--->
<cfset signatureMethod = new com.brianflove.oauth.methods.HmacSha1SignatureMethod()>

<!---sign request--->
<cfset oAuthRequest.signWithSignatureMethod(signatureMethod=signatureMethod)>

<!---POST using request URL--->
<cfset httpRequest = new Http()>
<cfset httpRequest.setUrl(oAuthRequest.getUrl())>
<cfset httpRequest.setMethod(oAuthRequest.getMethod())>
<cfset httpRequest.addParam(type="header", name="Authorization", value=oAuthRequest.toHeader())>
<cfset httpRequest.addParam(type="header", name="Accept", value="application/json") />
<cfset httpRequest.setCharset("utf-8")>
<cfset httpResult = httpRequest.send().getPrefix()>

<cfdump var="#httpResult.filecontent#">

错误回复:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse time="2016-12-01T06:12:00.999-08:00" xmlns="http://schema.intuit.com/finance/v3">
    <Fault type="AUTHENTICATION">
        <Error code="3200">
            <Message>message=ApplicationAuthenticationFailed; errorCode=003200; statusCode=401</Message>
            <Detail>SignatureBaseString: GET&amp;https%3A%2F%2Fsandbox-quickbooks.api.intuit.com%2Fv3%2Fcompany%2F123145723805019%2Fquery&amp;oauth_consumer_key%3DqyprdTVZH2CtDAXewG1YQKQYzUssYH%26oauth_nonce%3D420ADB0BF9EF309B785C531EEE8A7AAF%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1480601520%26oauth_token%3Dqyprd5g2WEiaxaVyI3MqeXqRvxvi26cXuauyMtFQaMZHdjVT%26oauth_version%3D1.0%26query%3Dselect%2520%252A%2520from%2520customer</Detail>
        </Error>
    </Fault>
</IntuitResponse>

1 个答案:

答案 0 :(得分:0)

在将查询语句传递给URL之前对其进行编码。

使用以下方法执行编码:

<cffunction name="encodePercent" returntype="string" access="public"
            description="RFC 3986 encoding - keep [ALPHA, DIGIT, '-', '.', '_', '~'], %-encode the rest -> decoding '~', correctly encoding spaces('+') and '*'">
    <cfargument name="sValue"       required="true" type="string" hint="value to encode">
    <cfargument name="sEncoding"    required="false" type="string" default="UTF-8" hint="encoding">
    <cfset var sResult = "">
    <!--- using javacast to call the appropriate encode method --->
    <cfif Len(arguments.sValue)>
        <cfset sResult = CreateObject("java","java.net.URLEncoder").
                            encode(JavaCast("String",arguments.sValue), JavaCast("String",arguments.sEncoding))>
        <cfset sResult = Replace(sResult,"+","%20","all")>
        <cfset sResult = Replace(sResult,"*","%2A","all")>
        <cfset sResult = Replace(sResult,"%7E","~","all")>
    </cfif>

    <cfreturn sResult>
</cffunction>

您可以保留&#34; sEncoding&#34;的默认值论证原样。