google-api - ColdFusion Google OAuth 获取访问令牌连接失败
问题描述
遵循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())>
解决方案
替换行
<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) & "&">
推荐阅读
- vba - 如何检查 2 个不同的值并删除找到其中任何一个值的文本?
- javascript - 在大括号内外打印代码有什么区别?
- sql-server - EF Core 中的 SQL Server 高效小计
- javascript - 使用 Webpack 4 时,BabelJS 正在处理错误的文件
- api - 如何在 wso2 API Store 中生成访问密钥?
- kotlin - 将 OutputStream 转换为 Okio 源
- regex - 如何使用“sed”自动更改配置文件?
- excel - VBA 多个 For 循环 - 仅在前两次正常工作
- r - brownian.bridge 计算缓慢和 area.grid[1, 1] 中的错误:维数不正确
- java - 实现 'com.android.support:appcompat-v7:28.0.0' 显示错误