1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00
This commit is contained in:
Michael Bleigh 2010-10-19 09:36:51 -05:00
commit 02c0f05af2
7 changed files with 90 additions and 3 deletions

View file

@ -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))

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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