Created
October 27, 2010 01:34
-
-
Save cbmeeks/648227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThirdpartyController < ApplicationController | |
before_filter :authenticate_user! | |
before_filter :get_consumer_info, :except => [ :index ] | |
def index | |
session[:request_token] = nil | |
end | |
def tripit | |
gem 'oauth' | |
require 'oauth/consumer' | |
session[:request_token] = nil | |
consumer = OAuth::Consumer.new @api_key, @api_secret, { :site => "https://api.tripit.com" } | |
callback = CGI::escape("http://example.com/thirdparty/tripit_callback") | |
request_token = consumer.get_request_token | |
oauth_token = request_token.token | |
request_url = "https://www.tripit.com/oauth/authorize?oauth_token=#{oauth_token}&oauth_callback=#{callback}" | |
request_token.consumer.secret = nil # do not pass the consumer secret via session | |
session[:request_token] = request_token | |
redirect_to request_url | |
end | |
def tripit_callback | |
request_token = session[:request_token] | |
request_token.consumer.secret = @api_secret | |
session[:request_token] = nil | |
access_token = request_token.get_access_token | |
# TODO | |
# STORE access_token and access_token_secret in DB | |
flash[:notice] = "Successfully authenticated TripIt!" | |
render :index | |
end | |
private | |
def get_consumer_info | |
@api_key = "MYAPIKEY" | |
@api_secret = "MYAPISECRET" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! Thanks