gpt4 book ai didi

coldfusion - Google 登录与 ColdFusion 的集成

转载 作者:行者123 更新时间:2023-12-04 02:17:09 24 4
gpt4 key购买 nike

我正在尝试将 ColdFusion 与 Google+ 集成。 grantType 有问题。首先,我使用 Google 对用户进行了身份验证。然后,当我尝试获取 token 时,它会抛出错误。下面是我的代码:

<cfset code  = URLEncodedFormat('#code#')>
<cfset appId = URLEncodedFormat('#this.appId#')>
<cfset key = URLEncodedFormat('#this.key#')>
<cfset uri = URLEncodedFormat('#this.redirectURI#')>
<cfset grant = 'authorization_code'>
<cfset postBody = "code=#code#"
& "&client_id=#appId#"
& "&client_secret=#key#"
& "&redirect_uri=#uri#"
& "&grant_type=#grant#">
<cfhttp url = "https://accounts.google.com/o/oauth2/token" method="POST">
<cfhttpparam type="body" value="#postBody#">
<cfhttpparam type="header" name="Conternt-Type" value="application/x-www-form-urlencoded">
</cfhttp>

这是错误:

{ "error" : "invalid_request", "error_description" : "Required parameter is missing: grant_type" }

我在这里做错了什么?我没有看到问题。请帮忙。

我已经关注了这个 https://developers.google.com/identity/protocols/OAuth2WebServer

最佳答案

有什么具体原因要自己搭建POST body吗?为了安全起见,试试这个(替换代码片段的所有行):

<cfhttp method="POST" url="https://accounts.google.com/o/oauth2/token">
<cfhttpparam type="formfield" name="grant_type" value="authorization_code">
<cfhttpparam type="formfield" name="redirect_uri" value="#this.redirectURI#">
<cfhttpparam type="formfield" name="client_id" value="#this.appId#">
<cfhttpparam type="formfield" name="client_secret" value="#this.key#">
<cfhttpparam type="formfield" name="code" value="#code#">
</cfhttp>

关于coldfusion - Google 登录与 ColdFusion 的集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33162169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com