2014-11-22 32 views
0

我在Safari中使用cfhttp時出現Google OAuth問題。它工作在我的本地環境,但在我們的託管環境中,每次我使用谷歌的OAuth,我得到下面的返回代碼:Coldfusion - Google OAuth2.0無法在Safari上的託管環境中工作

錯誤細節:

string 400 Bad Request 

文件內容:

string { "error" : "invalid_grant", "error_description" : "Code was already redeemed." } 

頁眉:

string HTTP/1.1 400 Bad Request Content-Type:application/json Cache-Control:no-cache,no-store,max-age = 0,必須重新驗證Pragma:no-cache過期時間:星期五,01 Jan 1990 00:00:00 GMT日期:2014年11月22日星期六01:38:30 GMT X-Content-Type-Options:nosniff X-Frame-Options:SAMEORIGIN X-XSS-Protection:1;模式=塊服務器:GSE複用協議:443:QUIC,p值= 0.02傳輸編碼:分塊

<cffunction name="getGoogleToken" access="public" output="false"> 
    <cfargument name="Event" type="any"> 
    <cfargument name="code" type="any"> 
    <cfset var rc = Event.getCollection() /> 
    <cfscript> 
     var postBody = "code=" & UrlEncodedFormat(arguments.code) & "&"; 
      postBody = postBody & "client_id=" & UrlEncodedFormat(rc.googleclientid) & "&"; 
      postBody = postBody & "client_secret=" & UrlEncodedFormat(rc.googleclientsecret) & "&"; 
      postBody = postBody & "redirect_uri=" & UrlEncodedFormat(rc.googlecallback) & "&"; 
      postBody = postBody & "grant_type=authorization_code"; 

    </cfscript> 
    <cfhttp url="https://accounts.google.com/o/oauth2/token" method="post" result="result" charset="utf-8"> 
     <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded"> 
     <cfhttpparam type="body" value="#postBody#"> 
    </cfhttp>    
    <cfdump var="#result#" /> 
    <cfabort> 
    <cfreturn deserializeJSON(result.filecontent.toString()) /> 
</cffunction> 
+0

使用帶硬編碼值的簡化cfhttp調用編寫測試頁。 Safari不會執行cfhttp請求。可能是Safari正在做兩個請求,其中第一個是使代碼過期。 – 2014-11-24 18:06:19

回答

2

「代碼已經兌換。」錯誤意味着您正嘗試使用已使用的授權碼。例如它調用兩個函數,因此兩次發送訪問令牌請求。請注意,給定的授權碼只能使用一次。