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

爱⌒轻易说出口 提交于 2020-02-03 23:41:53

问题


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


回答1:


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'



回答2:


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.




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/5017901/whats-the-correct-configuration-line-to-get-devise-omniauth-and-google-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!