spree-contrib / spree_social

Building block for spree social networking features (provides authentication and account linkage)
http://guides.spreecommerce.org
BSD 3-Clause "New" or "Revised" License
213 stars 283 forks source link

OmniAuth hardcoded info_fields #223

Open mightymatth opened 6 years ago

mightymatth commented 6 years ago

When using Facebook as OmniAuth provider, I want to retrieve first_name and last_name instead of name. The problem is located here where info_fields value is hardcoded to 'email, name' instead of being extendable (in my case to 'email, first_name, last_name'). Is there any reason why you hardcoded this? Also, is there any way to properly override this module method?

storhet commented 5 years ago

I'm having similar problem. I have custom omniauth gem which requires additional params to be passed (scope, base_uri) when we setup config.omniauth. And it will be great if there was a possibility to make setup_key_for method a bit more flexible

andretf commented 5 years ago

you can override by creating a decorator as defined here: https://github.com/spree-contrib/spree_social/blob/7963d4246b56e297e4ea7461e22bbe2a66ad20b7/lib/spree_social/engine.rb#L29:L33

ie: app/<some_path>/engine_decorator.rb:

OmniAuth::Strategies::Facebook.class_eval do
  def request_phase
    options[:scope] ||= 'email'
    options[:info_fields] = 'first_name,last_name,email'
    options[:display] = mobile_request? ? 'touch' : 'page'
    super
  end
end

I know it's not a definitive solution, I agree it should be dynamic, but it should work for now.