【问题标题】:ColdFusion Google OAuth get access token Connection FailedColdFusion Google OAuth 获取访问令牌连接失败
【发布时间】:2019-04-06 20:51:24
【问题描述】:

Ray Camden 为例。在我尝试获取访问令牌之前一切都很好。我的 getAccessToken() 函数因“连接失败”错误而爆炸。无法弄清楚我做错了什么?

<cfset authurl = "https://accounts.google.com/o/oauth2/v2/auth?" & 
"client_id=#urlEncodedFormat(application.clientid)#" & 
"&redirect_uri=#urlEncodedFormat(application.callback)#" & 
"&scope=https://www.googleapis.com/auth/userinfo.profile&response_type=code"> 
<cfoutput> 
authurl=#authurl#
<p><a href="#authurl#">Login</a></p> 
</cfoutput>

<cffunction name="getAccessToken"> 
<cfargument name="code" required="false" default="" type="string">
<cfset var postBody = "code=" & UrlEncodedFormat(arguments.code) & "&"> 
<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(this.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(this.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(this.callback) & "&"> 
<cfset postBody = postBody & "grant_type=authorization_code">

<cfhttp method="post" url="https://www.googleapis.com/oauth2/v4/token"> 
<cfhttpparam type="header" name="Content-Type"  value="application/x-www-form-urlencoded"> 
<cfhttpparam type="body" value="#postBody#">     
</cfhttp>   
<cfreturn deserializeJSON(cfhttp.filecontent.tostring())>

【问题讨论】:

  • 您可以从 ColdFusion 服务器访问 https://www.googleapis.com 吗?
  • 这很可能与用于通过 SSL (https) 连接的 cfhttp 相关。看看这个答案stackoverflow.com/a/20475763/8524758 以获得详细的解释并祝你好运!
  • 谢谢你们!您提供的链接中的说明解决了它!

标签: google-api coldfusion google-oauth coldfusion-2016


【解决方案1】:

替换行

<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(this.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(this.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(this.callback) & "&"> 

<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(application.clientid) & "&"> 
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(application.clientsecret) & "&"> 
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(application.callback) & "&"> 

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 2011-01-19
    • 2012-08-03
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 2013-05-26
    相关资源
    最近更新 更多