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

时间:2014-11-22 01:49:49

标签: oauth-2.0 google-oauth railo cfhttp

我在Safari中Google OAuth使用cfhttp时出现问题。它适用于我的本地环境,但每次使用google oauth时我们的托管环境都可以使用,我收到以下返回代码:

错误明细:

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,must-revalidate Pragma:no-cache Expires:Fri,1990年1月1日00:00:00 GMT日期:2014年11月22日星期六01:38:30 GMT X-Content-Type-Options:nosniff X-Frame-Options:SAMEORIGIN X-XSS-Protection:1; mode = block服务器:GSE Alternate-Protocol:443:quic,p = 0.02 Transfer-Encoding:chunked

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

1 个答案:

答案 0 :(得分:2)

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

相关问题