简体   繁体   中英

What's the correct configuration line to get devise, omniauth and google working?

I've looked through the documentation and I can't figure out the specific line I'm meant to use to get devise + omniauth + google working together nicely.

This strategy file suggests there's an easy way of doing it but I can't find an example.

https://github.com/intridea/omniauth/blob/master/oa-oauth/lib/omniauth/strategies/google.rb

At the moment I'm using the line below in the devise.rb initializer file.

config.omniauth :google, GOOGLE_APP_ID, GOOGLE_SECRET_KEY

but I'm pretty sure it's incomplete.

Also, I'm struggling to find where I should sign up for the google app id and secret key.

Thanks in advance. Graeme

Google is an openid implementation. Add the following in your initial file

provider :openid, OpenID::Store::Filesystem.new('./tmp'), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'

The line I used in the end was ...

config.omniauth :google, GOOGLE_APP_ID, GOOGLE_SECRET, :scope => "http://www.google.com/m8/feeds http://picasaweb.google.com/data/"

Turns out I was missing the scope I needed to access Picasa, which was what was causing me problems.

You may want to look at https://github.com/holden/devise-omniauth-example . In particular, look at the methods defined in user.rb , the user_token model they use, the devise views , and devise.rb . The last one in particular shows how you can configure devise/omniauth to work with google via openid: config.omniauth :google_apps, OpenID::Store::Filesystem.new('/tmp'), :domain => 'gmail.com' Hope it helps :)

I added the following lines to omniauth.rb and it worked like a charm:

Rails.application.config.middleware.use OmniAuth::Builder do  
   provider :openid, nil, :name => 'google', :identifier =>'https://www.google.com/accounts/o8/id'  
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM