2013-11-15 42 views
0

我得到什麼似乎是從Twitter的成功響應:Twitter Oauth:oauth_token_secret在哪裏?

/auth/twitter/callback?oauth_token=somelongtoken&oauth_verifier=someverifier 

但是沒有oauth_token_secret那裏。我在哪裏得到它?

DETAIL

routes.rb

get '/auth/:provider', to: 'authorisations#authorise', :as => :new_auth 
get '/auth/:provider/callback', to: 'authorisations#callback' 

authorisations_controller.rb

def authorise 
    session[:user_id] = current_user.id 
    @authorisation = Authorisation.new 
    @authorisation.user_id = current_user.id 
    if auth_hash.provider == "facebook" 
    @authorisation.provider = auth_hash.provider 
    @authorisation.oauth_token = auth_hash.credentials.token 
    @authorisation.oauth_expires_at = Time.at(auth_hash.credentials.expires_at) 
    elsif params[:provider] == "twitter" 
    @authorisation.provider = params[:provider] 
    @authorisation.oauth_token = params[:oauth_token] 
    @authorisation.oauth_token_secret = params[:oauth_token_secret] 
    @authorisation.access_token = params[:oauth_verifier] 
    end 
    @authorisation.save! 
end 

def callback 
    session[:user_id] = current_user.id 
    @authorisation = Authorisation.new 
    @authorisation.user_id = current_user.id 
    if auth_hash.provider == "facebook" 
    @authorisation.provider = auth_hash.provider 
    @authorisation.oauth_token = auth_hash.credentials.token 
    @authorisation.oauth_expires_at = Time.at(auth_hash.credentials.expires_at) 
    elsif params[:provider] == "twitter" 
    @authorisation.provider = params[:provider] 
    @authorisation.oauth_token = params[:oauth_token] 
    @authorisation.oauth_token_secret = params[:oauth_token_secret] 
    @authorisation.access_token = params[:oauth_verifier] 
    end 
    @authorisation.save! 
    redirect_to root_url, notice: "#{current_user.name} and #{params[:provider].titlecase} have been linked." 
end 

def auth_hash 
    request.env['omniauth.auth'] 
end 

documents_controller.rb

def twitter 
    session[:return_to] = request.referer 
    @document = Document.find(params[:id]) 
    if @document.template.name == "Image" 
    @document.process_social_media 
    twitter_user.update_with_media("#{@document.remove_html(@document.components.first.body[0..100])}...", "#{root_url}temporary#{@document.temp_file_name}.jpg") 
    else 
    twitter_user.update("#{@document.remove_html(@document.components.first.body[0..100])}... #{root_url.gsub(/\/$/, '')}#{share_path(@document.user.ftp, @document)}") 
    end 
    redirect_to session[:return_to], notice: "#{@document.title} has been posted to Twitter." 
end 

def twitter_user 
    user = Twitter.configure do |config| 
    config.consumer_key  = ENV['TWITTER_CONSUMER_KEY'] 
    config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] 
    config.oauth_token  = current_user.single_authorisation("twitter").oauth_token 
    config.oauth_token_secret = current_user.single_authorisation("twitter").oauth_token_secret 
    end 
end 
+0

您是否使用所有必需的參數發出了request_token? –

+0

有要求嗎?我只是在做Oauth的方式。將更新。 –

回答

0

它在這裏的人獵圍:

def create 
    @authorisation.oauth_token_secret = auth_hash.credentials.secret 
end 

def auth_hash 
    request.env['omniauth.auth'] 
end 

乾杯。

0

,因爲我做了這一點,已經有一段時間,所以也許它已經改變了,但這些參數我通過在授權請求:

oauth_consumer_key 
oauth_nonce 
oauth_signature 
oauth_signature_method 
oauth_timestamp 
oauth_version 
+0

雖然我已經有了一個創建請求的gem。我不確定我是否有能力控制它要求的內容? –