使用Google Oauth2客户端访问API时,Rails 3.2.3中的SSL错误
我是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凭据对用户进行身份validation时,我收到以下错误:
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凭据登录,没有任何问题。 我现在看到的问题是,当我尝试使用访问令牌(在用户身份validation期间从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')
生成错误
我一直在撞墙一段时间,有人有什么想法吗?
rest一下,谷歌搜索更多,还有更多的敲击声,我在https://gist.github.com/867550上遇到了非常优雅的解决方案。 设置SSL_CERT_FILE环境变量并重新启动我的机器修复了该问题。 哦是的,我忘了提到我正在开发一台Windows机器吗? 美好时光。