Omniauth-facebook hash not showing Facebook 'username' field, using rails 3 - ruby-on-rails

I've set up my rails 3 app to use omniauth-facebook, everything works fine but when I look at the omniauth hash as yaml there is no 'nickname' field, I can get the 'name' and 'email' but my validations fail to create a user because I can't grab the nickname for my app's username requirement.
I've double checked my facebook account, under "Settings", and my username is displayed. ANy ideas why this would be happening? Thanks for the help.
Here is an example of my omniauth hash, i've placed 'X' for privacy reason:
--- !ruby/hash:OmniAuth::AuthHash
provider: facebook
uid: 'XXXXXXXXXXXXX'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
email: XXXX#XXXX.XX
name: XXXX XXXX
first_name: XXXX
last_name: XXXX
image: http://graph.facebook.com/XXXXXXXXXXXXX/picture
urls: !ruby/hash:OmniAuth::AuthHash
Facebook: https://www.facebook.com/app_scoped_user_id/XXXXXXXXXXXXX/
verified: true
credentials: !ruby/hash:OmniAuth::AuthHash
token: ACCESS_TOKEN
expires_at: 1406357169
expires: true
extra: !ruby/hash:OmniAuth::AuthHash
raw_info: !ruby/hash:OmniAuth::AuthHash
id: 'XXXXXXXXXXXXXXX'
email: XXXX#XXXX.XX
first_name: XXXX
gender: male
last_name: XXXX
link: https://www.facebook.com/app_scoped_user_id/XXXXXXXXXXXXX/
locale: en_US
name: XXXX XXXX
timezone: 7
updated_time: '2014-05-07T00:58:12+0000'
verified: true

There's no field nickname, do you mean username? If so it's no longer available if you use the Graph API v2.0.
References:
https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/#fields

I know this is an old question.
Since facebook now does not support fetching username at time of login, a workaround for getting user name would be, to call GraphRequest.newMeRequest() from the onSuccess() method of facebook login button

Related

how Inject headers to OmniAuth mock tests

I'm using omniauth-google-oauth2 gem to log in via google account. recently I saw this post https://developers.googleblog.com/2020/08/guidance-for-our-effort-to-block-less-secure-browser-and-apps.html. even though it will not affect to the regular users I'm worried about unit tests. which i guess use headless browsers. so I would like to test that by injecting headers as described in this post(Google-Accounts-Check-OAuth-Login:true). couldn't find any api methods for that on omiauth documentations.
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new(
provider: "google",
uid: "123545",
info: {
email: EMAIL,
first_name: FIRST_NAME,
last_name: LAST_NAME,
}
)
visit new_user_registration_path
click_link "Sign in with Google"

omniauth_saml with auth0 as the provider. Can not get user_metadata it returns "[object Object]"

I am using multiple idps. One is OKTA and one is Auth0 but I found out I need a little bit more information about the user which is in the user_metadata for auth0. When the data is returned its coming back as "[object Object]" I also am using devise.
devise.rb
config.omniauth :saml_okta,
name: :saml_okta,
strategy_class: ::OmniAuth::Strategies::SAML,
idp_cert_fingerprint: ENV['OKTA_CERT'],
idp_sso_target_url: ENV['OKTA_SSO']
config.omniauth :saml_auth0,
name: :saml_auth0,
strategy_class: ::OmniAuth::Strategies::SAML,
idp_cert_fingerprint: ENV['AUTH0_CERT'],
idp_sso_target_url: ENV['AUTH0_SSO'],
attribute_statements: {email: ['http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress'],
user_metadata: ['http://schemas.auth0.com/user_metadata/'] }
But the data that is returned looks like this:
provider: :saml_auth0
uid: foo#gmail.com
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: foo#gmail.com
email: foo#gmail.com
first_name:
last_name:
user_metadata: "[object Object]"
How can I get the user_metadata ?

Translate devise labels in registration?

I want to translate my labels in registration form, but I can't see what is the schema to follow in my .es locale. It wont work with "registrations". Someone knows? I can't find a correct answer in all the internet. Thanks
.es locale
devise:
registrations:
name: "Nombre"
email: "Email"
password: "ContraseƱa"
password_confirmation: "Recordarme"
It's done via active record translations
es:
activerecord:
attributes:
user:
password: "ContraseƱa"
email: "Email"
password_confirmation: "Recordarme"

Retrieving Google profile picture with Omniauth on Rails 3

I'm starting a new Rails 3 app using Omniauth for authentication via Facebook, Twitter and Google. I can easily get the user's avatar from Facebook and Twitter, but can't find a way to retrieve it from Google, if existent.
Here's the code I use to build the authentication hash:
omniauth['user_info']['email'] ? #authhash[:email] = omniauth['user_info']['email'] : #authhash[:email] = ''
omniauth['user_info']['name'] ? #authhash[:name] = omniauth['user_info']['name'] : #authhash[:name] = ''
omniauth['uid'] ? #authhash[:uid] = omniauth['uid'].to_s : #authhash[:uid] = ''
omniauth['provider'] ? #authhash[:provider] = omniauth['provider'] : #authhash[:provider] = ''
On Twitter and Facebook this next line gets the avatar or sets to the default if not provided:
omniauth['user_info']['image'] ? #authhash[:image] = omniauth['user_info']['image'] : #authhash[:image] = 'avatar.jpg'
This doesn't work on Google and I couldn't find any documentation on that.
Any ideas?
Thanks a lot!
Try 'Omniauth Google OAuth2 Strategy' in which a commit states:
Returns name, first_name, last_name, image, email in info with :scope => 'userinfo.email,userinfo.profile'
You can view the commit here
Yes you can get the picture, though i would imagine it depends on what versions your using.
im using
rvm current
ruby-1.9.3-p194
> gem list
oauth (0.4.6)
oauth2 (0.8.0)
omniauth (1.1.0, 1.0.3)
omniauth-facebook (1.4.1, 1.4.0)
omniauth-google (1.0.1)
omniauth-google-oauth2 (0.1.13)
omniauth-oauth (1.0.1)
omniauth-oauth2 (1.1.0, 1.0.3)
omniauth-twitter (0.0.12)
I arrived here for a different reason that was due to the fact that the naming convention to access the profile properties was different from those explain in various tutorials, as such i was experiencing error completing the sign in. In fact in your question you may find that you will have the same issues.
The problem is that google has different property names from FB, Twitter, etc. so you have to account for that.
To find the properties i commented out the doing bit, and just dumped the response out. like so.
elsif service_route == 'google_oauth2'
render :text => omniauth.to_yaml
return
This will output your google profile details which will hopefully look like the following.
--- !ruby/hash:OmniAuth::AuthHash
provider: google_oauth2
uid: '1234567'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: Your Name
email: yourEmail
first_name: firstname
last_name: surname
image: https://animage
credentials: !ruby/hash:Hashie::Mash
token: aToken
expires_at: 123
expires: true
extra: !ruby/hash:Hashie::Mash
raw_info: !ruby/hash:Hashie::Mash
id: '123456'
email: YourEmail
verified_email: true
name: YourName
given_name: Name
family_name: surname
link: https://plus.google.com/blah
picture: https://lh6.googleusercontent.com/blah blah
gender: male
birthday: ''
locale: en-GB
As you can see the names of the parameters are different, get rid of user_info and instead have info.
You will also notice that you have picture: and image: so whilst i have not tried this i would assume that it is your profile picture.
elsif service_route == 'google_oauth2'
omniauth['info']['email'] ? email = omniauth['info']['email'] : email = ''
omniauth['info']['name'] ? name = omniauth['info']['name'] : name = ''
omniauth['uid'] ? uid = omniauth['uid'] : uid = ''
omniauth['provider'] ? provider = omniauth['provider'] : provider = ''
omniauth['info']['image'] ? image = omniauth['info']['image'] : image = ''
I was having the same issue and found out that it was just that the image of the profile wasn't public. I had to change the settings from 'Visible only to people I can chat with' to 'Visible to everyone'. Then the image started to show up. Hope this helps someone.

Troubleshooting 'Unknown record property / related component "user" on "sfGuardUserProfile"' when loading fixture data

I am some trouble loading fixture data, that I have added manually in my admin backend and then simply exported the data using 'symfony doctrine:data-dump'
schema.yml
http://pastebin.com/5LTzNtU1
fixtures.yml (snippet)
http://pastebin.com/CNWyhrgc
Now everything works fine when I run symfony doctrine:build --all, but when i try to load the data, I get:
Unknown record property / related component "user" on "sfGuardUserProfile"
This is really odd, as I have saved users and they've gone into both tables fine, just not when loading the fixtures that I exported fomr the database.
Does anyone have any ideas what the problem could be?
Thanks
Try this. create users.yml with
sfGuardUser:
sfGuardUser_1:
email_address: test#example.com
username: test_user
algorithm: sha1
salt: 6fdcd99a2c73d6270f1ed8dbbf7ccd3e
password: fed98ad16c318197d16a2d7375f81e1afbce0792
is_active: true
is_super_admin: true
last_login: '2011-05-03 09:37:08'
first_name: ''
last_name: ''
created_at: '2011-04-11 11:29:02'
updated_at: '2011-05-03 09:37:08'
and profile.yml with
sfGuardUserProfile:
sfGuardUserProfile_1:
User: sfGuardUser_1
email_new: test#example.com
firstname: Test
lastname: User
validate_at: null
validate: null
created_at: '2011-04-19 15:46:16'
updated_at: '2011-04-19 15:49:14'
Maybe it help you.

Resources