gpt4 book ai didi

ruby-on-rails - 使用 Google Oauth2 客户端访问 API 时 Rails 3.2.3 中的 SSL 错误

转载 作者:数据小太阳 更新时间:2023-10-29 08:05:10 26 4
gpt4 key购买 nike

我是 OAuth2 的新手,我正在尝试使用 Omniauth 和 Google API 客户端通过 Google API 访问用户的 Blogger 帐户。我正在使用以下内容:

  • rails 3.2.3
  • ruby 1.9.3
  • oauth2 (0.8.0)
  • omniauth (1.1.1)
  • omniauth-google-oauth2 (0.1.13)
  • google-api-client (0.4.6)

当我第一次尝试使用 Google 凭据对用户进行身份验证时,我收到了以下错误:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

但是,当我在初始化程序中将特定路径添加到我的 CA 证书时,错误消失了:

provider :google_oauth2, ENV['GOOGLE_APP_ID'], ENV['GOOGLE_SECRET'], {
access_type: "offline",
approval_prompt: "",
scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/blogger',
client_options: { ssl: { ca_file: cert_path } }
}

因此,现在我的用户可以毫无问题地使用他们的 Google 凭据登录。我现在看到的问题是,当我尝试使用访问 token (在用户身份验证期间从 Google 收到)访问 Blogger API 时,我再次遇到 SSL 错误。这是我用来访问 API 的代码:

token = auth.first.oauth_token.access_token   # access token received during authentication

client = Google::APIClient.new
client.authorization.access_token = token
service = client.discovered_api('blogger', 'v3')
result = client.execute(
:api_method => service.blog_list.list,
:parameters => {},
:headers => {'Content-Type' => 'application/json'})

错误在 service = client.discovered_api('blogger', 'v3') 行中生成

我已经用头撞墙了一段时间了,有人有什么想法吗?

最佳答案

休息一会后,又用谷歌搜索了一番,又敲了敲脑袋,我在 https://gist.github.com/867550 找到了一个非常优雅的解决方案。 .设置 SSL_CERT_FILE 环境变量并重新启动我的机器解决了这个问题。哦对了,我是不是忘了说我是在 Windows 机器上开发的?好时光。

关于ruby-on-rails - 使用 Google Oauth2 客户端访问 API 时 Rails 3.2.3 中的 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12520314/

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