Linked In authentication and aggregate data

泄露秘密 提交于 2019-12-08 03:51:22

问题


I'm building a web app with Ruby on Rails and I want my users to authenticate and aggregate data from Linked In (and others like Github, Twitter, etc...).

I am using these gems:

  • Devise for registration
  • omniauth-linkedin for authentication
  • pengwynn/linkedin for data aggregation

Though, Linked In has a not-so-nice pin thing. Is there a way to avoid it and get the data I want from my users account without having them to go to linked in, fetch a pin and submit it to me?

Thanks in advance.

authentications_controller.rb

class AuthenticationsController < ApplicationController
  def index
    @authentications = current_user.authentications if current_user
  end

  def create
    omniauth = request.env["omniauth.auth"]
    authentication = Authentication.
          find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
    if authentication
      flash[:notice] = "Signed in successfully."
      sign_in_and_redirect(:user, authentication.user)
    elsif current_user
      current_user.authentications.
            create!(provider: omniauth['provider'], uid: omniauth['uid'])
      current_user.apply_omniauth(omniauth)
      flash[:notice] = "Authentication successful."
      redirect_to authentications_url
    else
      user = User.new
      user.apply_omniauth(omniauth)
      if user.save
        flash[:notice] = "Signed in successfully."
        sign_in(:user, user)
        redirect_to user_path(user.username)
      else
        session[:omniauth] = omniauth.except('extra')
        redirect_to new_user_registration_url
      end
   end
end

来源:https://stackoverflow.com/questions/13576185/linked-in-authentication-and-aggregate-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!