Permalink
Browse files

Merge branch 'master' of github.com:intridea/omniauth

  • Loading branch information...
2 parents 0754174 + 3ac27ae commit 6094ca423c83057df1230797c19f317ad1e617d8 Michael Bleigh committed May 20, 2011
View
4 Gemfile
@@ -4,10 +4,6 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
end
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec :path => 'oa-basic'
gemspec :path => 'oa-core'
gemspec :path => 'oa-enterprise'
View
2 README.md
@@ -41,13 +41,15 @@ OmniAuth currently supports the following external providers:
* Miso (credit: [rickenharp](https://github.com/rickenharp))
* Mixi (credit: [kiyoshi](https://github.com/kiyoshi))
* Netflix (credit: [caged](https://github.com/caged))
+ * Plurk (credit: [albb0920](http://github.com/albb0920))
* Qzone (credit: [quake](https://github.com/quake))
* Rdio (via [brandonweiss](https://github.com/brandonweiss))
* Renren (credit: [quake](https://github.com/quake))
* Salesforce (via [CloudSpokes](http://www.cloudspokes.com))
* SmugMug (credit: [pchilton](https://github.com/pchilton))
* SoundCloud (credit: [leemartin](https://github.com/leemartin))
* T163 (credit: [quake](https://github.com/quake))
+ * Taobao (credit: [l4u](https://github.com/l4u))
* TeamBox (credit [jrom](https://github.com/jrom))
* Tqq (credit: [quake](https://github.com/quake))
* TradeMe (credit: [pchilton](https://github.com/pchilton))
View
4 oa-basic/Gemfile
@@ -4,8 +4,4 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
end
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec
View
2 oa-basic/oa-basic.gemspec
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake', '~> 0.8'
gem.add_development_dependency 'rspec', '~> 2.5'
gem.add_development_dependency 'webmock', '~> 1.6'
- # gem.add_development_dependency 'yard', '~> 0.7'
+ gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.name = 'oa-basic'
gem.version = OmniAuth::Version::STRING
View
4 oa-core/Gemfile
@@ -1,7 +1,3 @@
source 'http://rubygems.org'
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec
View
2 oa-core/oa-core.gemspec
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rack-test', '~> 0.5'
gem.add_development_dependency 'rake', '~> 0.8'
gem.add_development_dependency 'rspec', '~> 2.5'
- # gem.add_development_dependency 'yard', '~> 0.7'
+ gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.name = 'oa-core'
gem.version = OmniAuth::Version::STRING
View
4 oa-enterprise/Gemfile
@@ -4,8 +4,4 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
end
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec
View
2 oa-enterprise/oa-enterprise.gemspec
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake', '~> 0.8'
gem.add_development_dependency 'rspec', '~> 2.5'
gem.add_development_dependency 'webmock', '~> 1.6'
- # gem.add_development_dependency 'yard', '~> 0.7'
+ gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.name = 'oa-enterprise'
gem.version = OmniAuth::Version::STRING
View
41 oa-enterprise/spec/omniauth/strategies/ldap_spec.rb
@@ -0,0 +1,41 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'cgi'
+
+describe OmniAuth::Strategies::LDAP, :type => :strategy do
+
+ include OmniAuth::Test::StrategyTestCase
+
+ def strategy
+ @ldap_server ||= 'ldap.example.org'
+ [OmniAuth::Strategies::LDAP, {
+ :host => @ldap_server,
+ :port => 636,
+ :method => :ssl,
+ :uid => 'jeremyf',
+ :base => 'o="University of OmniAuth", st=Sublime, c=RubyNation',
+ }]
+ end
+
+ describe 'GET /auth/ldap' do
+ before do
+ get '/auth/ldap'
+ end
+
+ # TODO: Add checks that page has authentication form; I attempted
+ # to use `should have_tag` but that was not working.
+ it 'should get authentication page' do
+ last_response.status.should == 200
+ end
+ end
+
+ describe 'POST /auth/ldap' do
+ before do
+ post '/auth/ldap', {:username => 'jeremy', :password => 'valid_password' }
+ end
+
+ it 'should redirect us to /auth/ldap/callback' do
+ last_response.should be_redirect
+ last_response.location.should == '/auth/ldap/callback'
+ end
+ end
+end
View
4 oa-more/Gemfile
@@ -4,8 +4,4 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
end
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec
View
2 oa-more/oa-more.gemspec
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec', '~> 2.5'
gem.add_development_dependency 'simplecov', '~> 0.4'
gem.add_development_dependency 'webmock', '~> 1.6'
- # gem.add_development_dependency 'yard', '~> 0.7'
+ gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.name = 'oa-more'
gem.version = OmniAuth::Version::STRING
View
4 oa-oauth/Gemfile
@@ -4,8 +4,4 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
end
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec
View
2 oa-oauth/lib/omniauth/oauth.rb
@@ -28,12 +28,14 @@ module Strategies
autoload :Mixi, 'omniauth/strategies/mixi'
autoload :Netflix, 'omniauth/strategies/netflix'
autoload :Qzone, 'omniauth/strategies/qzone'
+ autoload :Plurk, 'omniauth/strategies/plurk'
autoload :Rdio, 'omniauth/strategies/rdio'
autoload :Renren, 'omniauth/strategies/renren'
autoload :Salesforce, 'omniauth/strategies/salesforce'
autoload :SmugMug, 'omniauth/strategies/smug_mug'
autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
autoload :T163, 'omniauth/strategies/t163'
+ autoload :TB, 'omniauth/strategies/taobao'
autoload :Teambox, 'omniauth/strategies/teambox'
autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
autoload :Tqq, 'omniauth/strategies/tqq'
View
16 oa-oauth/lib/omniauth/strategies/oauth2.rb
@@ -64,16 +64,7 @@ def callback_phase
end
@access_token = build_access_token
-
- if @access_token.expires? && @access_token.expires_in <= 0
- client.request(:post, client.access_token_url, {
- 'client_id' => client_id,
- 'grant_type' => 'refresh_token',
- 'client_secret' => client_secret,
- 'refresh_token' => @access_token.refresh_token
- }.merge(options))
- @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
- end
+ @access_token = client.web_server.refresh_access_token(@access_token.refresh_token) if @access_token.expired?
super
rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
@@ -84,11 +75,8 @@ def callback_phase
fail!(:timeout, e)
end
- def verifier
- request.params['code']
- end
-
def build_access_token
+ verifier = request.params['code']
client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
end
View
58 oa-oauth/lib/omniauth/strategies/plurk.rb
@@ -0,0 +1,58 @@
+require 'omniauth/oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ #
+ # Authenticate to Plurk via OAuth and retrieve basic user info.
+ #
+ # Please note that this strategy relies on Plurk API 2.0,
+ # which is still in Beta.
+ #
+ # Usage:
+ # use OmniAuth::Strategies::Plurk
+ class Plurk < OmniAuth::Strategies::OAuth
+
+ # @param [Rack Application] app standard middleware application parameter
+ # @param [String] client_key App key [registered on plurk] (http://www.plurk.com/PlurkApp/register)
+ # @param [String] client_secret App secret registered on plurk
+ def initialize(app, client_key = nil, client_secret = nil, options = {}, &block)
+ client_options = { :site => 'http://www.plurk.com',
+ :request_token_path => '/OAuth/request_token',
+ :access_token_path => '/OAuth/access_token',
+ :authorize_path => '/OAuth/authorize' }
+
+ super(app, :plurk, client_key, client_secret, client_options, options)
+ end
+
+ def auth_hash
+ user = self.user_hash
+ OmniAuth::Utils.deep_merge(super, {
+ 'uid' => user['id'],
+ 'user_info' => user_info,
+ 'extra' => {'user_hash' => user_hash}
+ })
+ end
+
+ def user_info
+ user = self.user_hash
+ {
+ 'name' => user['full_name'],
+ 'nickname' => user['display_name'] || user['nick_name'],
+ 'location' => user['location'],
+ 'image' => if user['has_profile_image'] == 1
+ "http://avatars.plurk.com/#{user['id']}-medium#{user['avatar']}.gif"
+ else
+ "http://www.plurk.com/static/default_medium.gif"
+ end,
+ 'urls' => { 'Plurk' => 'http://plurk.com/' + user['nick_name']}
+ }
+ end
+
+ def user_hash
+ @user_hash ||= MultiJson.decode(@access_token.get('/APP/Profile/getOwnProfile').body)['user_info']
+ end
+
+ end
+ end
+end
View
79 oa-oauth/lib/omniauth/strategies/taobao.rb
@@ -0,0 +1,79 @@
+require 'omniauth/oauth'
+require 'multi_json'
+require 'digest/md5'
+require 'net/http'
+
+module OmniAuth
+ module Strategies
+ # Authenticate to Renren utilizing OAuth 2.0 and retrieve
+ # basic user information.
+ #
+ # @example Basic Usage
+ # use OmniAuth::Strategies::TB, 'client_id', 'client_secret'
+ class TB < OAuth2
+ # @param [Rack Application] app standard middleware application parameter
+ # @param [String] client_id the app key at taobao open platform
+ # @param [String] client_secret the app secret at taobao open platform
+ # @option options [String]
+
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
+ client_options = {
+ :site => "https://oauth.taobao.com/",
+ :authorize_url => "/authorize",
+ :access_token_url => "/token"
+ }
+
+ super(app, :tb, client_id, client_secret, client_options, options, &block)
+ end
+
+ def user_data
+ # TODO to be moved in options
+ url = 'http://gw.api.taobao.com/router/rest'
+
+ query_param = {
+ :app_key => client_id,
+
+ # TODO to be moved in options
+ # TODO add more default fields (http://my.open.taobao.com/apidoc/index.htm#categoryId:1-dataStructId:3)
+ :fields => 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind',
+ :format => 'json',
+ :method => 'taobao.user.get',
+ :session => @access_token.token,
+ :sign_method => 'md5',
+ :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
+ :v => '2.0'
+ }
+ query_param = generate_sign(query_param)
+ res = Net::HTTP.post_form(URI.parse(url), query_param)
+ @data ||= MultiJson.decode(res.body)["user_get_response"]["user"]
+ end
+
+ def request_phase
+ options[:state] ||= '1'
+ super
+ end
+
+ def user_info
+ {
+ 'name' => user_data["nick"],
+ 'email' => (user_data["email"] if user_data["email"]),
+ }
+ end
+
+ def auth_hash
+ OmniAuth::Utils.deep_merge(super, {
+ 'uid' => user_data['uid'],
+ 'user_info' => user_info,
+ 'extra' => {'user_hash' => user_data}
+ })
+ end
+
+ def generate_sign(params)
+ str = client_secret + (params.sort.collect { |k, v| "#{k}#{v}" }).join + client_secret
+ params["sign"] = Digest::MD5.hexdigest(str).upcase!
+ params
+ end
+
+ end
+ end
+end
View
2 oa-oauth/oa-oauth.gemspec
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec', '~> 2.5'
gem.add_development_dependency 'simplecov', '~> 0.4'
gem.add_development_dependency 'webmock', '~> 1.6'
- # gem.add_development_dependency 'yard', '~> 0.7'
+ gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.name = 'oa-oauth'
gem.version = OmniAuth::Version::STRING
View
5 oa-oauth/spec/omniauth/strategies/plurk_spec.rb
@@ -0,0 +1,5 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe OmniAuth::Strategies::Plurk do
+ it_should_behave_like 'an oauth strategy'
+end
View
5 oa-oauth/spec/omniauth/strategies/taobao_spec.rb
@@ -0,0 +1,5 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+
+describe OmniAuth::Strategies::TB do
+ it_should_behave_like "an oauth2 strategy"
+end
View
4 oa-openid/Gemfile
@@ -4,8 +4,4 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.7'
end
-group :development do
- gem 'yard', :git => 'https://github.com/lsegal/yard.git'
-end
-
gemspec
View
2 oa-openid/oa-openid.gemspec
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec', '~> 2.5'
gem.add_development_dependency 'simplecov', '~> 0.4'
gem.add_development_dependency 'webmock', '~> 1.6'
- # gem.add_development_dependency 'yard', '~> 0.7'
+ gem.add_development_dependency 'yard', '~> 0.7'
gem.add_development_dependency 'ZenTest', '~> 4.5'
gem.name = 'oa-openid'
gem.version = OmniAuth::Version::STRING

0 comments on commit 6094ca4

Please sign in to comment.