0
在我session_controller.rb我有這樣的:的Rails 3 LinkedIn寶石(如何獲得令牌後跨視圖操作認證)
require 'linkedin'
class SessionController < ApplicationController
def connect
# 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 callback
client = LinkedIn::Client.new(APP_CONFIG['linkedin']['apikey'], APP_CONFIG['linkedin']['secret_key'])
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
這工作得很好,我現在的問題是如何在檢查'用戶/索引'行動無論用戶是否已經通過Linkedin的OAuth流程?下面是我想要做的開始:
class UsersController < ApplicationController
respond_to :html, :js, :json
def index
if authenticated?
# set up a new LinkedIn client and show profile data
else
redirect_to 'session/connect'
end
end
...
private
def authenticated?
# what should i do here?
# return true if the user authenticated
# return false if not
end
我知道我可能應該檢查是否有一定的價值在會話設置,但我不知道我在找到底是哪一個。我知道將來我可能會推動'認證'?方法,所以它被稱爲所有的意見,但是這是好的。
任何幫助?謝謝!
+1謝謝你的回答,抱歉,遲到的迴應。我會試試這:) – botbot