Coldfusion - Google OAuth2.0无法在Safari上的托管环境中工作

问题描述:

我在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

“代码已经兑换。”错误意味着您正尝试使用已使用的授权码。例如它调用两个函数,因此两次发送访问令牌请求。请注意,给定的授权码只能使用一次。