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
Related
I have a rails 4.2.7 app setup using the omniauth-google-oauth2 gem, and I would like to retrieve the first_name and last_name from the auth hash.
I was able to do this with the omniauth-facebook gem by modifying the devise.rb to look like the following,
devise.rb
# Omniauth / Oauth2 settings
callback_url = if Rails.env == "development"
ENV['FB_CALLBACK']
else
ENV['FB_CALLBACK_PROD']
end
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], callback_url: callback_url,
:scope => 'email',
:info_fields => 'email, first_name, last_name'
# Google - OmniAuth
require 'omniauth-google-oauth2'
config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"]
However, I can't seem to figure out how to retrieve the first_name / last_name using omniauth-google-oauth2. Any help would greatly be appreciated.
#chris from omniauth-google-oauth2, in your callback controller action,
auth = request.env['omniauth.auth']
request.env['omniauth.auth'] will contain a hash of users' auth session, with which basic user info are persisted in info i.e. auth["info"]
auth
====
{
.....
"info"=>
{"name"=>"Username",
"email"=>"Useremail",
"first_name"=>"firstname",
"last_name"=>"lastname",
"image"=> "image_url",
"urls"=>{"Google"=>"https://plus.google.com/xxxxxxxxxxxxxxxxx"}
}
....
}
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
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)
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'}}}
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