Omniauth Facebook doesnt return the extra data - ruby-on-rails

I tried with everything that show up in google or here but doesn't work
its just show me the basic info (name,id,photo)
here s my code for omniauth.rb:
provider :facebook, 'key', 'key', {:scope => 'email',:info_fields => 'email', :client_options => {:ssl => {:ca_file => Rails.root.join("cacert.pem").to_s}}}
and this is how i call it:
auth = request.env["omniauth.auth"]
session[:omniauth] = auth

Related

Mocking google with omniauth in rails integration test

I have a sample project, where user can login with their google account, Now i want to write a test to verify that user has successfully logged in with his google account. But i don't know how to verify this thing in my test file ?
This is what i have tried now but its not working
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({
:provider => 'google',
:uid => '1337',
:info => {
'name' => 'JonnieHallman',
'email' => 'jon#test.com'
}
request.env["devise.mapping"] = Devise.mappings[:user]
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
I am supposing that after this my page content would change but they are same as before
You can follow the guide on how to do integration tests with Omniauth https://github.com/intridea/omniauth/wiki/Integration-Testing
basically you'll have something like this in your spec/rails_helper.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:xing] = OmniAuth::AuthHash.new({
:provider => 'google',
:uid => '123545',
:info => {
:name => "Test",
:email => "test#test.com"
},
:credentials => {
:token => "token",
:secret => "secret"
}
# etc.
})
And then have a login_helper that does something like
def login
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
visit root_path
click_link 'loginBtn'
end

omniauth-facebook Gem: omniauth.auth sometimes has nil provider and uid?

My application is authenticating users with the omniauth-facebook gem version 1.6.0. It seems that sometimes within the facebook action in the OmniauthCallbacksController, the request.env["omniauth.auth"] hash will have nil values for provider and uid.
I would appreciate any insight into why this would happen. Here's the relevant code from my omniauth config initializer
config.omniauth :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
{:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}

Rails - Devise+OmniAuth: how to set up credentials for staging version?

In /config/initializers/devise.rb I have something like this:
# production
config.omniauth :facebook, 'aaa', 'bbb',
:site => 'https://graph.facebook.com',
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:scope => 'email'
# staging version
config.omniauth :facebook, 'ccc', 'ddd',
:site => 'https://graph.facebook.com',
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:scope => 'email'
When I put these 2 blocks of code into the devise.rb file, I get the error saying that there are incorrect credentials.
I don't know what's the best approach to set up OmniAuth credentials to services like Twitter and Facebook for devise - the one I used is apparently incorrect.
What's the best approach to set up credentials for localhost, production and staging version of an app?
Thanks
It seems that your credentials are wrong for localhost. I have two versions of creditals for development and production, here is example
if Rails.env.development?
config.omniauth :facebook, "xxx", "yyy"
config.omniauth :vkontakte, "xxx_loc", "yyy_loc"
else
config.omniauth :facebook, "zzz", "rrr"
config.omniauth :vkontakte, 'zzz_loc', 'rrr_loc'
end
at /config/initializers/devise.rb
case Rails.env
when "production"
# production version
config.omniauth :facebook, 'aaa', 'bbb',
:site => GRAPH_URL,
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:scope => 'email'
when "staging"
# staging version
config.omniauth :facebook, 'ccc', 'ddd',
:site => GRAPH_URL,
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:scope => 'email'
else
# development version
config.omniauth :facebook, 'eee', 'fff',
:site => GRAPH_URL,
:authorize_path => '/oauth/authorize',
:access_token_path => '/oauth/access_token',
:scope => 'email'
end
The best way to handle different credentials is to put them in environment variables, just like omniauth gem doc says:
https://github.com/intridea/omniauth#getting-started
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
end
This approach has several advantages:
It keeps your configuration simple
No credentials in code repository
It doesn't limit you to dev/test/prod

rails omniauth facebook extended permission

I have read the omniauth oauth rdoc
#consumer = OAuth::Consumer.new(key, secret, {
:site => "http://term.ie",
:scheme => :header,
:http_method => :post,
:request_token_path => "/oauth/example/request_token.php",
:access_token_path => "/oauth/example/access_token.php",
:authorize_path => "/oauth/example/authorize.php"
})
there is no scope such as
https://graph.facebook.com/oauth/authorize?
client_id=...&
redirect_uri=http://www.example.com/callback&
scope=user_photos,user_videos,publish_stream
How do I add one? I am trying to overwrite oauth now ... do anyone got any better solution?
Put this in initializer
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook , 'app' , 'secret' , {:scope => "manage_pages"}
end
If you are using more than one scope, it's comma delimited:
:scope => "offline_access, manage_pages"

Has anyone used omniauth with rails 2.3.8?

I am new to Rails and I am trying to use omniauth with rails 2.3.8. I
couldn't find any tutorial for this version of rails so I referred to
http://blog.railsrumble.com/blog/2010/10/08/intridea-omniauth.
I added the initializer as follows:
omniauth.rb
OmniAuth::Strategies::Twitter = {
:consumer_key => 'xxxxxx',
:consumer_secret => 'xxxxxx'
}
After this step if I try to hit the URL '/auth/twitter' then I get "No
route matches "/auth/twitter" with {:method=>:get}".
Has anyone used omniauth with rails 2.3.8?
OmniOauth is a Rack::Middleware. So you need use it like that.
So you need add like that :
ActionController::Dispatcher.middleware.use OmniAuth::Strategies::Twitter = {
:consumer_key => 'xxxxxx',
:consumer_secret => 'xxxxxx'
}
This is how it works for me in rails 2.3.8
omniauth.rb:
ActionController::Dispatcher.middleware.use OmniAuth::Builder do
provider :facebook,
"key", "secret",
:scope => %(email user_birthday publish_stream offline_access),
:client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
end

Resources