【问题标题】:SSL Error in Rails 3.2.3 while using Google Oauth2 client to access APIRails 3.2.3 中使用 Google Oauth2 客户端访问 API 时出现 SSL 错误
【发布时间】:2012-09-13 06:33:29
【问题描述】:

我是 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 凭据登录。我现在看到的问题是,当我尝试使用访问令牌(在用户身份验证期间从 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') 行中正在生成错误

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

【问题讨论】:

    标签: ruby-on-rails ruby oauth-2.0 ssl-certificate google-api-client


    【解决方案1】:

    休息一下,再用谷歌搜索,再敲敲头,我在https://gist.github.com/867550 发现了一个非常优雅的解决方案。设置 SSL_CERT_FILE 环境变量并重新启动我的机器解决了这个问题。哦,是的,我忘了提到我正在 Windows 机器上开发吗?好时光。

    【讨论】:

    • 知道如何在 linux 机器上完成这个任务吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2019-01-17
    • 1970-01-01
    • 2013-01-15
    • 2014-02-15
    相关资源
    最近更新 更多