【问题标题】:Coldfusion - Google OAuth2.0 not working in hosted environment on SafariColdfusion - Google OAuth2.0 无法在 Safari 上的托管环境中工作
【发布时间】:2015-01-20 07:06:51
【问题描述】:

我在 Safari 中使用 cfhttp 时遇到了 Google OAuth 的问题。它适用于我的本地环境,但在我们的托管环境中,每次我使用 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, 01 Jan 1990格林威治标准时间 00:00:00 日期:2014 年 11 月 22 日星期六 01:38:30 格林威治标准时间 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>

【问题讨论】:

  • 使用带有硬编码值的简化 cfhttp 调用编写测试页面。 Safari 不执行 cfhttp 请求。可能是 Safari 正在执行两个请求,第一个请求是使代码过期。

标签: oauth-2.0 google-oauth railo cfhttp


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-31
    • 2020-03-21
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 2021-08-01
    • 2021-07-30
    • 2017-04-30
    相关资源
    最近更新 更多