Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grab a higher resolution photo? #22

Open
abrambailey opened this issue Sep 24, 2014 · 11 comments
Open

Grab a higher resolution photo? #22

abrambailey opened this issue Sep 24, 2014 · 11 comments

Comments

@abrambailey
Copy link

Is it possible. The photo is pretty terrible. Thanks

@abrambailey
Copy link
Author

@ishields
Copy link

ishields commented Mar 2, 2018

@abrambailey It seems this link is dead. I'm seeing a lot of places suggest adding "picture-urls::(original)" to the field in devise.rb

config.omniauth :linkedin, app_key, app_secret,
                      scope: 'r_basicprofile r_emailaddress',
                      fields: %w(id email-address first-name last-name picture-urls::(original))

but this does not seem to work. I get all of the other fields but no additional picture urls are returned. At first I thought linkedin changed their api but it still references this field in their documentation.

@abrambailey
Copy link
Author

I did this ... abrambailey@58b732e

Then in omniauth callbacks controller

  def linkedin
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.find_for_linkedin_oauth2(request.env["omniauth.auth"])
    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "LinkedIn"
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.linkedin_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

Then in user.rb

  def self.find_for_linkedin_oauth2(access_token, signed_in_resource=nil)
    data = access_token.info
    user = User.where(:email => data["email"]).first
     unless user
       if (data[:image][:values] rescue nil) != nil
         url = data[:image][:values][0]
         user = User.create(
            username: data["name"],
            email: data["email"],
            password: Devise.friendly_token[0,20],
            role_ids: [Role.find_by(name: "dispenser").id],
            avatar: open(url)
         )
       else
         user = User.create(
            username: data["name"],
            email: data["email"],
            password: Devise.friendly_token[0,20],
            role_ids: [Role.find_by(name: "dispenser").id]
         )
       end
     end
    user
  end

@ishields
Copy link

ishields commented Mar 2, 2018

Hmmm and this still works for you as of today? - I'm doing something very similar. I've added the "'picture-urls::(original)'" to fields as well (did this in devise.rb instead) but "url = data[:image][:values][0]" never returns anything.

@abrambailey
Copy link
Author

https://www.hearingtracker.com/users/sign_in

Try it and let me know. Just fill in your name and sex, and I'll remove your account.

@ishields
Copy link

ishields commented Mar 2, 2018

image

Doesn't seem like it worked :(

@abrambailey
Copy link
Author

Well crap. Thanks for noticing this bug. I guess no one reported it to me, and we weren't testing it.

@abrambailey
Copy link
Author

Not even sure when it stopped working.

@abrambailey
Copy link
Author

I'm actually amazed that I caught it this quickly. Thanks @ishields !

@abrambailey
Copy link
Author

Deleted your user account, email, etc, from our server. Fwiw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants