Вопрос

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:

  • 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)

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

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 } }
}

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'})

The error is being generated in the line 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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top