Rails, get circledByCount with omniauth-google-oauth2 - ruby-on-rails

I use omniauth-google-oauth2 gem and want to get all people in my circle on google plus account, my omniauth file:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV['twitter_key'], ENV['twitter_secret'], info_fields: 'followers_count'
provider :instagram, ENV['instagram_key'], ENV['instagram_secret'], info_fields: 'follows'
provider :facebook, ENV['facebook_key'], ENV['facebook_secret'], info_fields: 'friends'
google_scope = "plus.login"
provider :google_oauth2, ENV['google_key'], ENV['google_secret'], scope: google_scope, access_type: "offline"
end
but request.env['omniauth.auth'] return:
"id_info"=>
{"iss"=>"accounts.google.com",
"at_hash"=>"secret",
"aud"=>"secret",
"sub"=>"secret",
"azp"=>"secret",
"iat"=>1445275484,
"exp"=>1445279084},
"raw_info"=>
{"kind"=>"plus#personOpenIdConnect",
"gender"=>"male",
"sub"=>"103458288129240855409",
"name"=>"Sergey Naumenko",
"given_name"=>"Sergey",
"family_name"=>"Naumenko",
"profile"=>"https://plus.google.com/103458288129240855409",
"picture"=>"https://lh6.googleusercontent.com/-b8p4jlJRIm8/AAAAAAAAAAI/AAAAAAAAAV4/rZXezwwCy7w/photo.jpg?sz=50",
"locale"=>"en"}}}
I need get circledByCount
Who can help me?

I fixed it with adding option skip_friends: false
provider :google_oauth2, ENV['google_key'], ENV['google_secret'], scope: google_scope, skip_friends: false

Related

Oauth 2 "redirect_uri_mismatch: { "error" : "redirect_uri_mismatch" }" in rails

I am using oauth2 gem for google login auth. My code looks like
omniauth.rb
OmniAuth.config.logger = Rails.logger
require "omniauth-google-oauth2"
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, 'secret-client-id', 'secret-number', {client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end
my routes.rb
get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')
my view
<%= link_to "Sign in with Google", "/auth/google_oauth2", id: "sign_in" %>
I am getting this URL after this pages
Where am i going wrong?
Try adding token to the omniauth initializer:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, "id", "secret", {
client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}},
scope: 'email profile',
access_type: 'online',
setup: (lambda do |env|
request = Rack::Request.new(env)
env['omniauth.strategy'].options['token_params'] = {:redirect_uri => 'http://.../auth/google_oauth2/callback'}
end)
}
end

Rails: Get user's email after Facebook Oauth (using Devise & facebook omniauth gem)

I'm having trouble accessing a user's email, first_name, and last_name after they signup from Facebook.
Here's what my Omniauth.rb looks like:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'],
:scope => 'email',
:info_fields=>'first_name, last_name, email'
end
When the Facebook login window shows up, it shows the scope properly ("this app will have access to your email"). But when I pry into the response, I see that I'm not getting any of my requested fields back.
{"provider"=>"facebook",
"uid"=>"10101161800900201",
"info"=>
{"name"=>"Jackson Cunningham",
"image"=>"http://graph.facebook.com/10101161800900201/picture"},
"credentials"=>
{"token"=>
"...",
"expires_at"=>1445243073,
"expires"=>true},
"extra"=>
{"raw_info"=>
{"name"=>"Jackson Cunningham", "id"=>"10101161800900201"}}}
Figured it out. You just need to make sure to edit Devise.rb in addition to Omniauth.rb
Devise.rb should have:
config.omniauth :facebook, "your_facebook_id", "your_facebook_secret", scope: 'email,public_profile', info_fields: 'email, first_name, last_name'
replacing whatever specific info_fields you need (list of all available here)

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: Twitter Omniauth gem 401 Unauthorized Error

I am using twitter omniauth gem in my web application. I stored my key and secret in my DB.
This is my middleware code
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, lambda { Site.config[:twitter][:key] },lambda{ Site.config[:twitter][:secret] }
end
This returns unauthorized error.
But when i specify my key and secret directly in the middleware it works.
(i.e)
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "consumer_key" , "consumer_secret"
end
What is wrong with my first approach ?
You need to use Setup Phase
provider :twitter, :setup => true
And then in controller:
def setup
request.env['omniauth.strategy'].options[:consumer_key] = Site.config[:twitter][:key]
request.env['omniauth.strategy'].options[:consumer_secret] = Site.config[:twitter][:secret]
render :text => "Setup complete.", :status => 404
end
Routes:
match '/auth/:provider/setup' => 'sessions#setup' # for example
You can add your consumer_key and consumer secret in the development.rb and production.rb
# twitter api credential
config.twitt_consumer_key = 'xxxxxxxxxxxxxxxxx'
config.twitt_consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
And then you can use it
provider :twitter, Rails.application.config.twitt_consumer_key, Rails.application.config.twitt_consumer_secret

Get facebook app id from config/initializers/devise.rb

I've set my facebook app id in config/initializers/devise.rb and now i'm trying to retrieve it in my controller.
How do I call it back?
Devise.setup do |config|
config.omniauth :facebook, 'XXXXXX', 'XXXXX', :scope => 'email,offline_access,user_likes,user_interests,publish_actions,publish_stream'
end
Devise.omniauth_configs[:facebook].strategy.client_id

Resources