ruby-on-rails – 新的LinkedIn权限问题(Rails omniauth-linkedi
我在我的rails应用程序中使用omniauth-linkedin gem:
https://github.com/skorks/omniauth-linkedin 它应该考虑新的LinkedIn权限请求过程和范围,但我没有成功获取电子邮件地址或完整配置文件(除默认配置文件概述之外的任何其他内容). 这是我的omniauth.rb文件: Rails.application.config.middleware.use OmniAuth::Builder do provider :linkedin,ENV['LINKEDIN_KEY'],ENV['LINKEDIN_SECRET'],:scope => 'r_fullprofile r_emailaddress' end 在用户输入她/他的凭据之前,完整的个人资料和电子邮件地址请求最初会进入LinkedIn.但是,一旦用户登录,范围请求就会丢失,并且只能访问默认的配置文件概述信息. 我认为我的问题与必须在我想要的范围内专门请求那些字段有关,如gem页面(https://github.com/skorks/omniauth-linkedin)中所述.尽管如此,我还是尝试向omniauth.rb文件添加特定字段请求但没有成功(下面的电子邮件字段请求): Rails.application.config.middleware.use OmniAuth::Builder do provider :linkedin,:scope => 'r_fullprofile+r_emailaddress',:fields => ["id","email-address","first-name","last-name","headline","industry","picture-url","public-profile-url","location","positions","educations"] end 显然,除了非默认字段(如电子邮件地址,职位和教育)之外,我还应该请求配置文件概述的默认字段,以便访问后面的非默认字段. LinkedIn电子邮件地址应该是直截了当的,因为它不是像职位或教育这样的结构化对象,而且我相信我缺少我想要的职位和教育中的特定领域的代码(不知道我会怎么写并且会喜欢一些输入也是如此).我正在使用我的新API密钥,所以我不确定问题是什么.我需要LinkedIn的某种特殊许可吗?感谢帮助!谢谢. 另外,这是我的auth控制器的相关代码: require 'linkedin' class AuthController < ApplicationController def auth client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'],ENV['LINKEDIN_SECRET']) request_token = client.request_token(:oauth_callback => "http://#{request.host_with_port}/callback") session[:rtoken] = request_token.token session[:rsecret] = request_token.secret redirect_to client.request_token.authorize_url end def callback client = LinkedIn::Client.new(ENV['LINKEDIN_KEY'],ENV['LINKEDIN_SECRET']) if current_user.atoken.nil? && current_user.asecret.nil? pin = params[:oauth_verifier] atoken,asecret = client.authorize_from_request(session[:rtoken],session[:rsecret],pin) current_user.atoken = atoken current_user.asecret = asecret current_user.uid = client.profile(:fields => ["id"]).id flash.now[:success] = 'Signed in with LinkedIn.' elsif current_user.atoken && current_user.asecret client.authorize_from_access(current_user.atoken,current_user.asecret) flash.now[:success] = 'Signed in with LinkedIn.' end 解决方法
不确定这是否是最优雅的解决方案,但这对我有用
我刚添加了配置,其中包含在request_token_path中传递的范围 LINKEDIN_CONFIGURATION = { :site => 'https://api.linkedin.com',:authorize_path => '/uas/oauth/authenticate',:request_token_path =>'/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress+r_network+r_contactinfo',:access_token_path => '/uas/oauth/accessToken' } client = LinkedIn::Client.new(LINKEDIN_API_KEY,LINKEDIN_SECRET_KEY,LINKEDIN_CONFIGURATION ) 其余代码是一样的. 一定要在回调方法中更改客户端构造函数. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |