我从Twitter获得了一个似乎是成功的回应:
/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 :(得分:0)
我做了这个已经有一段时间了,所以也许它已经改变了,但这些是我在授权请求中传递的参数:
oauth_consumer_key
oauth_nonce
oauth_signature
oauth_signature_method
oauth_timestamp
oauth_version
答案 1 :(得分:0)
这是任何人在附近狩猎:
def create
@authorisation.oauth_token_secret = auth_hash.credentials.secret
end
def auth_hash
request.env['omniauth.auth']
end
干杯。