diff --git a/README.markdown b/README.markdown index f3b464f..fc36ec8 100644 --- a/README.markdown +++ b/README.markdown @@ -24,6 +24,8 @@ OmniAuth currently supports the following external providers: * GitHub * Identi.ca (credit: [dcu](http://github.com/dcu)) * Gowalla (credit: [kvnsmth](http://github.com/kvnsmth)) + * Dopplr (credit: [flextrip](http://github.com/flextrip)) + * TripIt (credit: [flextrip](http://github.com/flextrip)) * OpenID * Google Apps (via OpenID) * CAS (Central Authentication Service) (credit: [jamesarosen](http://github.com/jamesarosen)) diff --git a/oa-oauth/lib/omniauth/oauth.rb b/oa-oauth/lib/omniauth/oauth.rb index a6d2ea4..51d6369 100644 --- a/oa-oauth/lib/omniauth/oauth.rb +++ b/oa-oauth/lib/omniauth/oauth.rb @@ -13,5 +13,7 @@ module OmniAuth autoload :Foursquare, 'omniauth/strategies/foursquare' autoload :Gowalla, 'omniauth/strategies/gowalla' autoload :Identica, 'omniauth/strategies/identica' + autoload :Tripit, 'omniauth/strategies/tripit' + autoload :Dopplr, 'omniauth/strategies/dopplr' end end diff --git a/oa-oauth/lib/omniauth/strategies/dopplr.rb b/oa-oauth/lib/omniauth/strategies/dopplr.rb new file mode 100644 index 0000000..87a3158 --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/dopplr.rb @@ -0,0 +1,22 @@ +require 'omniauth/oauth' + +module OmniAuth + module Strategies + # + # Authenticate to Dopplr via OAuth and retrieve an access token for API usage + # + # Usage: + # + # use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret' + # + class Dopplr < OmniAuth::Strategies::OAuth + def initialize(app, consumer_key, consumer_secret) + super(app, :dopplr, consumer_key, consumer_secret, + :site => 'https://www.dopplr.com', + :request_token_path => "/oauth/request_token", + :access_token_path => "/oauth/access_token", + :authorize_path => "/oauth/authorize") + end + end + end +end diff --git a/oa-oauth/lib/omniauth/strategies/facebook.rb b/oa-oauth/lib/omniauth/strategies/facebook.rb index fafbcd9..476901c 100644 --- a/oa-oauth/lib/omniauth/strategies/facebook.rb +++ b/oa-oauth/lib/omniauth/strategies/facebook.rb @@ -7,7 +7,7 @@ module OmniAuth # basic user information. # # @example Basic Usage - # use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret' + # use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret' class Facebook < OAuth2 # @param [Rack Application] app standard middleware application parameter # @param [String] app_id the application id as [registered on Facebook](http://www.facebook.com/developers/) @@ -19,7 +19,7 @@ module OmniAuth end def user_data - @data ||= MultiJson.decode(@access_token.get('/me')) + @data ||= MultiJson.decode(@access_token.get('/me', {}, { "Accept-Language" => "en-us,en;"})) end def request_phase @@ -49,4 +49,4 @@ module OmniAuth end end end -end +end \ No newline at end of file diff --git a/oa-oauth/lib/omniauth/strategies/tripit.rb b/oa-oauth/lib/omniauth/strategies/tripit.rb new file mode 100644 index 0000000..3f49adb --- /dev/null +++ b/oa-oauth/lib/omniauth/strategies/tripit.rb @@ -0,0 +1,35 @@ +require 'omniauth/oauth' + +module OmniAuth + module Strategies + # + # Authenticate to TripIt via OAuth and retrieve an access token for API usage + # + # Usage: + # + # use OmniAuth::Strategies::TripIt, 'consumerkey', 'consumersecret' + # + class Tripit < OmniAuth::Strategies::OAuth + def initialize(app, consumer_key, consumer_secret) + super(app, :tripit, consumer_key, consumer_secret, + :site => 'https://api.tripit.com', + :request_token_path => "/oauth/request_token", + :access_token_path => "/oauth/access_token", + :authorize_url => "https://www.tripit.com/oauth/authorize") + end + + def request_phase + request_token = consumer.get_request_token(:oauth_callback => callback_url) + (session[:oauth]||={})[name.to_sym] = {:callback_confirmed => request_token.callback_confirmed?, :request_token => request_token.token, :request_secret => request_token.secret} + r = Rack::Response.new + # For some reason, TripIt NEEDS the &oauth_callback query param or the user receives an error. + r.redirect request_token.authorize_url + "&oauth_callback=" + urlencode(callback_url) + r.finish + end + + def urlencode(str) + str.gsub(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) } + end + end + end +end diff --git a/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb b/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb new file mode 100644 index 0000000..2ebd6a8 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb @@ -0,0 +1,13 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe 'OmniAuth::Strategies::Dopplr' do + + it 'should subclass OAuth' do + OmniAuth::Strategies::Dopplr.should < OmniAuth::Strategies::OAuth + end + + it 'should initialize with just consumer key and secret' do + lambda{OmniAuth::Strategies::Dopplr.new({},'abc','def')}.should_not raise_error + end + +end diff --git a/oa-oauth/spec/omniauth/strategies/tripit_spec.rb b/oa-oauth/spec/omniauth/strategies/tripit_spec.rb new file mode 100644 index 0000000..b0ce6e5 --- /dev/null +++ b/oa-oauth/spec/omniauth/strategies/tripit_spec.rb @@ -0,0 +1,13 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe 'OmniAuth::Strategies::Tripit' do + + it 'should subclass OAuth' do + OmniAuth::Strategies::Tripit.should < OmniAuth::Strategies::OAuth + end + + it 'should initialize with just consumer key and secret' do + lambda{OmniAuth::Strategies::Tripit.new({},'abc','def')}.should_not raise_error + end + +end