Google oauth令牌给出405错误 [英] Google oauth token giving 405 error
问题描述
我想使用下面的代码发布。我希望它返回令牌,但返回错误405方法不允许。
I am trying to post using below Code. I expect it to return token but its returning error 405 Method Not Allowed.
<cfhttp method="POST" url="http://accounts.google.com/o/oauth2/token" >
<cfhttpparam type="Formfield" name="code" value="#url.CODE#">
<cfhttpparam type="Formfield" name="client_id" value="458381219741.apps.googleusercontent.com">
<cfhttpparam type="Formfield" name="client_secret" value="XXXXXXX">
<cfhttpparam type="Formfield" name="redirect_uri" value="http://console.mbwebportal.com/oauth2callback">
<cfhttpparam type="Formfield" name="grant_type" value="authorization_code">
</cfhttp>
上述代码位于 http://console.mbwebportal.com/oauth2callback ,并且在用户允许访问应用程序后,它会在网址中获取代码。
The above code is on http://console.mbwebportal.com/oauth2callback and it gets the Code in url after user allows access to the application.
请帮助!!
推荐答案
我发现答案:键是使用cfhttpparam类型' body '。
As per livedocsbody:指定HTTP请求的主体ColdFusion不会自动设置内容类型头或URL对主体内容进行编码要指定内容类型,请使用单独的cfhttp标记类型=
I found the answer: key was to use cfhttpparam type 'body'. As per livedocs "body: specifies the body of the HTTP request. ColdFusion does not automatically set a content-type header or URL encode the body contents. To specify the content-type, use a separate cfhttp tag with type=header. "
以下代码现在返回了我的访问令牌:
Below code is returning me access token now :)
<cfset client_id = "458381219741.apps.googleusercontent.com">
<cfset client_secret = "**********">
<cfset callback = "http://console.mbwebportal.com/oauth2callback">
<cfset postBody = "code=" & UrlEncodedFormat(url.code) & "&">
<cfset postBody = postBody & "client_id=" & UrlEncodedFormat(client_id) & "&">
<cfset postBody = postBody & "client_secret=" & UrlEncodedFormat(client_secret) & "&">
<cfset postBody = postBody & "redirect_uri=" & UrlEncodedFormat(callback) & "&">
<cfset postBody = postBody & "grant_type=authorization_code">
<cfhttp method="post" url="https://accounts.google.com/o/oauth2/token">
<cfhttpparam name="Content-Type" type="header" value="application/x-www-form-urlencoded">
<cfhttpparam type="body" value="#postBody#">
</cfhttp>
这篇关于Google oauth令牌给出405错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!