gpt4 book ai didi

ruby-on-rails - 谷歌 auth1 到 oauth2 迁移 : Invalid authorization header

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:48 25 4
gpt4 key购买 nike

我有一个脚本可以使用 oauth gem 从 google oauth1 迁移到 oauth2

一切似乎都正确,我无法检测到 header 有任何问题,但它仍然响应:无效的授权 header 。

这是标题:

opening connection to accounts.google.com:443... opened starting SSL for accounts.google.com:443... SSL established <- "POST /o/oauth2/token HTTP/1.1\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: /\r\nUser-Agent: OAuth gem v0.4.7\r\nContent-Length: 193\r\nAuthorization: OAuth oauth_consumer_key=\"mykey.com\", oauth_nonce=\"LdBeaxxxxxxxxxxxxxxIxgd03U1DHYbs\", oauth_signature=\"wXIuxxxxxxxyxxxxj0%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1416497830\", oauth_token=\"1%2F9G2sKmQxxxxxxxxxxmDXbqqifoRBGUAii-D5sw2o\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: accounts.google.com\r\n\r\n"

<- "client_id=the_id&client_secret=C-7xxxxxxxxxboMcinh3ofV&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Amigration%3Aoauth1"> "HTTP/1.1 400 Bad Request\r\n"

-> "Content-Type: application/json\r\n"

-> "Cache-Control: no-cache, no-store, max-age=0, must-revalidate\r\n"

-> "Pragma: no-cache\r\n"

-> "Expires: Fri, 01 Jan 1990 00:00:00 GMT\r\n"

-> "Date: Thu, 20 Nov 2014 12:37:03 GMT\r\n"

-> "X-Content-Type-Options: nosniff\r\n"

-> "X-Frame-Options: SAMEORIGIN\r\n"

-> "X-XSS-Protection: 1; mode=block\r\n"

-> "Server: GSE\r\n"

-> "Alternate-Protocol: 443:quic,p=0.01\r\n"

-> "Connection: close\r\n"

-> "\r\n"

reading all...

-> "{\n \"error\" : \"invalid_request\",\n \"error_description\" : \"Invalid authorization header.\"\n}"

read 90 bytes Conn close

代码如下:

oauth1_consumer_key    = "mykey"
oauth1_consumer_secret = "Gxxxxxxxxxxxxxxxxqb8"

# OAuth 1 - User Token / Secret.
oauth1_token = '1/9G2xxxxxxxxxxxxxxsw2o'
oauth1_secret = 'a-xxxxxxxxxxxxxxxmqG'

# OAuth 2 - Application ID / Secret
oauth2_client_id = "the_id"
oauth2_client_secret = "C-xxxxxxxxxxxxxxxxV"

# Migration Parameters.
params = {
"grant_type" => "urn:ietf:params:oauth:grant-type:migration:oauth1",
"client_id" => oauth2_client_id,
"client_secret" => oauth2_client_secret,
# "oauth_signature_method" => "HMAC-SHA1"
}

# Create the consumer object.
consumer = OAuth::Consumer.new(
oauth1_consumer_key,
oauth1_consumer_secret,
:site => 'https://accounts.google.com',
:scheme => :header
)


# Create the access token object.
access_token = OAuth::AccessToken.new(consumer, oauth1_token, oauth1_secret)

resp = access_token.post(
"/o/oauth2/token",
params,
{ 'Content-Type' => 'application/x-www-form-urlencoded' })

if resp.code.to_s != "200"
# Raise an error.
raise "#{resp.code} - #{resp.body}"
end

有什么想法吗?

最佳答案

更新oauth gem后,我再次尝试,成功了。

关于ruby-on-rails - 谷歌 auth1 到 oauth2 迁移 : Invalid authorization header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27040167/

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