我正在使用 Ruby on Rails 构建一个 Web 应用程序,我希望我的用户能够验证和聚合来自 Linked In(以及其他类似 Github、Twitter 等)的数据。
我正在使用这些宝石:
- 设计注册
- 用于身份验证的omniauth-linkedin
- pengwynn/linkedin 用于数据聚合
不过,Linked In 有一个不太好的 pin 东西。
有没有办法避免它并从我的用户帐户获取我想要的数据,而无需他们去链接,获取 pin 并将其提交给我?
提前致谢。
身份验证控制器.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
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)