Ruby on Rails を使用して Web アプリを構築しています。ユーザーが認証を行い、Linked In (および Github、Twitter などの他のアプリ) からのデータを集約できるようにしたいと考えています。
私はこれらの宝石を使用しています:
- 登録の工夫
- 認証用の omniauth-linkedin
- データ集約のための pengwynn/linkedin
ただし、Linked In にはあまり良くないピンがあります。それを回避し、ユーザー アカウントから必要なデータを取得する方法はありますか?
前もって感謝します。
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