使用Google Oauth2客户端访问API时,Rails 3.2.3中出现SSL错误 [英] SSL Error in Rails 3.2.3 while using Google Oauth2 client to access API

查看:103
本文介绍了使用Google Oauth2客户端访问API时,Rails 3.2.3中出现SSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OAuth2还是很陌生,我正在尝试使用Omniauth和Google API客户端通过Google API访问用户的Blogger帐户.我正在使用以下内容:

I'm fairly new to OAuth2 and I'm trying to access a user's Blogger account through the Google API with Omniauth and the Google API client. I'm using the following:

  • 导轨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凭据对用户进行身份验证时,出现以下错误:

When I first tried to authenticate a user with Google credentials, I received the following error:

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

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

However, when I added the specific path to my CA certs in the initializer, the error went away:

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的代码:

So, now my user can login with their Google credentials with no problem. The issue I'm now seeing is that when I try to use the access token (received from Google during user authentication) to access the Blogger API, I get the SSL error again. This is the code I'm using to access the 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')

我已经将头撞墙了一段时间了,有人有什么主意吗?

I've been banging my head against the wall for a while now, anyone have any ideas?

推荐答案

休息片刻之后,再进行一些谷歌搜索和更多的敲打动作,我在

After taking a break, some more Googling, and more head banging, I came across the wonderfully elegant solution at https://gist.github.com/867550. Setting the SSL_CERT_FILE environment variable and restarting my machine fixed the issue. Oh yeah, did I forget to mention I'm developing on a Windows machine? Good times.

这篇关于使用Google Oauth2客户端访问API时,Rails 3.2.3中出现SSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆