Linkedin Ruby Gem(令牌在回调中被拒绝)

时间:2012-06-13 02:30:11

标签: ruby-on-rails ruby oauth linkedin

我一直在使用LinkedIn Ruby Gem并遇到问题。这是我的rails服务器的输出。

Started GET "/session/callback?oauth_token=618b3bc2-d8f6-4c9c-99a2-10573c8b3c3c&oauth_verifier=09858" for 127.0.0.1 at Tue Jun 12 19:14:11 -0700 2012
Processing by SessionController#callback as HTML
  Parameters: {"oauth_verifier"=>"09858", "oauth_token"=>"618b3bc2-d8f6-4c9c-99a2-10573c8b3c3c"}
Completed 500 Internal Server Error in 163ms

OAuth::Problem (token_rejected):
  app/controllers/session_controller.rb:28:in `callback'


  Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
  Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.9ms)

以下是我的session_controller.rb中的代码:

require 'linkedin'

class SessionController < ApplicationController

  def login

    # get your api keys at https://www.linkedin.com/secure/developer
    client = LinkedIn::Client.new(APP_CONFIG['linkedin']['apikey'], APP_CONFIG['linkedin']['secret_key'])
    request_token = client.request_token(:oauth_callback => 
                                      "http://#{request.host_with_port}/session/callback")
    session[:rtoken] = request_token.token
    session[:rsecret] = request_token.secret

    redirect_to client.request_token.authorize_url

  end

  def logout
    session[:atoken] = nil
    redirect_to :root
  end

  def callback

    client = LinkedIn::Client.new(APP_CONFIG['linkedin']['apikey'], APP_CONFIG['linkedin']['secret_key']) # "your_api_key", "your_secret")
    if session[:atoken].nil?
      pin = params[:oauth_verifier]
      atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin)
      session[:atoken] = atoken
      session[:asecret] = asecret
    else
      client.authorize_from_access(session[:atoken], session[:asecret])
    end

    redirect_to '/users/index'

  end

end

我也有随机访问问题,这是错误:

Access Denied
You don't have permission to access "/D/16382/14334/000/origin.wwwapps.ups.com/uas/oauth/authorize?oauth_token=730c3a62-08ad-4ac2-9281-c9e67bb3a2d5" on this server.

Reference #18.6fd054b8.1339554485.72cbb3 

1 个答案:

答案 0 :(得分:2)

请注意这是否是这个问题的最终答案,但在开发过程中帮助我的一件事就是清除缓存和cookie。通常会出现此错误,因为前一个会话中设置的cookie会使系统混乱并触发此错误。