From f4919a113acc0e28dfe655bcb2f1e0c626976536 Mon Sep 17 00:00:00 2001 From: "James A. Rosen" Date: Sun, 13 Jun 2010 16:36:59 -0400 Subject: [PATCH] Bundler's add_bundler_dependencies is considered harmful and being deprecated; changed from Gemfile -> .gemspec dependencies to the reverse. --- Gemfile | 30 ---------- Rakefile | 6 +- development_dependencies.rb | 20 +++++++ oa-basic/Gemfile | 9 +++ oa-basic/Rakefile | 4 +- oa-basic/dist/oa-basic-0.0.3/CHANGELOG.rdoc | 3 + oa-basic/dist/oa-basic-0.0.3/LICENSE.rdoc | 0 oa-basic/dist/oa-basic-0.0.3/README.rdoc | 34 +++++++++++ .../dist/oa-basic-0.0.3/lib/omniauth/basic.rb | 10 ++++ .../lib/omniauth/strategies/basecamp.rb | 55 ++++++++++++++++++ .../lib/omniauth/strategies/campfire.rb | 47 ++++++++++++++++ .../lib/omniauth/strategies/gowalla.rb | 19 +++++++ .../lib/omniauth/strategies/http_basic.rb | 56 +++++++++++++++++++ oa-basic/oa-basic.gemspec | 9 ++- oa-core/Gemfile | 7 +++ oa-core/Rakefile | 4 +- oa-core/oa-core.gemspec | 4 +- oa-oauth/Gemfile | 9 +++ oa-oauth/Rakefile | 4 +- oa-oauth/oa-oauth.gemspec | 12 +++- oa-openid/Gemfile | 9 +++ oa-openid/Rakefile | 4 +- oa-openid/oa-openid.gemspec | 6 +- omniauth/Gemfile | 12 ++++ omniauth/Rakefile | 2 +- omniauth/omniauth.gemspec | 4 +- 26 files changed, 322 insertions(+), 57 deletions(-) delete mode 100644 Gemfile create mode 100644 development_dependencies.rb create mode 100644 oa-basic/Gemfile create mode 100644 oa-basic/dist/oa-basic-0.0.3/CHANGELOG.rdoc create mode 100644 oa-basic/dist/oa-basic-0.0.3/LICENSE.rdoc create mode 100644 oa-basic/dist/oa-basic-0.0.3/README.rdoc create mode 100644 oa-basic/dist/oa-basic-0.0.3/lib/omniauth/basic.rb create mode 100644 oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/basecamp.rb create mode 100644 oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/campfire.rb create mode 100644 oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/gowalla.rb create mode 100644 oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/http_basic.rb create mode 100644 oa-core/Gemfile create mode 100644 oa-oauth/Gemfile create mode 100644 oa-openid/Gemfile create mode 100644 omniauth/Gemfile diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 1339fd8..0000000 --- a/Gemfile +++ /dev/null @@ -1,30 +0,0 @@ -source "http://rubygems.org" - -gem 'rack', '~> 1.1.0' - -group :oa_basic, :oa_oauth do - gem 'json', '~> 1.4.3' - gem 'nokogiri', '~> 1.4.2' -end - -group :oa_basic do - gem 'rest-client', '~> 1.5.1', :require => 'restclient' -end - -group :oa_oauth do - gem 'oauth', '~> 0.4.0' - gem 'oauth2', '~> 0.0.8' -end - -group :oa_openid do - gem 'rack-openid', '~> 1.0.3', :require => 'rack/openid' -end - -group :development do - gem 'rake' - gem 'mg', '~> 0.0.8' - gem 'term-ansicolor', :require => 'term/ansicolor' - gem 'rspec', '~> 1.3.0', :require => 'spec' - gem 'webmock', '~> 1.2.2' - gem 'rack-test', '~> 0.5.4', :require => 'rack/test' -end diff --git a/Rakefile b/Rakefile index 6686f9f..05b0437 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,4 @@ require 'rubygems' -require 'bundler' -Bundler.setup(:development) require 'rake' require 'term/ansicolor' @@ -59,14 +57,14 @@ namespace :gems do task :build do each_gem('is building gems...') do system('rake gem') - end + end end desc 'Push all gems to Gemcutter' task :release do each_gem('is releasing to Gemcutter...') do system('rake gemcutter') - end + end end desc 'Install all gems' diff --git a/development_dependencies.rb b/development_dependencies.rb new file mode 100644 index 0000000..9ab04bb --- /dev/null +++ b/development_dependencies.rb @@ -0,0 +1,20 @@ +# to be evaluated within the context of a Gemspec or a Gemfile + +# It's ridiculous that Bundler can't sync up with .gemspec files for +# development dependencies. Until it can, make sure to keep these +# two blocks parallel. +if Object.const_defined?(:Bundler) && Bundler.const_defined?(:Dsl) && self.kind_of?(Bundler::Dsl) + group :development do + gem 'rake' + gem 'mg', '~> 0.0.8' + gem 'rspec', '~> 1.3.0' + gem 'webmock', '~> 1.2.2' + gem 'rack-test', '~> 0.5.4' + end +else #gemspec + gem.add_development_dependency 'rake' + gem.add_development_dependency 'mg', '~> 0.0.8' + gem.add_development_dependency 'rspec', '~> 1.3.0' + gem.add_development_dependency 'webmock', '~> 1.2.2' + gem.add_development_dependency 'rack-test', '~> 0.5.4' +end diff --git a/oa-basic/Gemfile b/oa-basic/Gemfile new file mode 100644 index 0000000..08d393c --- /dev/null +++ b/oa-basic/Gemfile @@ -0,0 +1,9 @@ +source "http://rubygems.org" + +gem 'oa-core', :path => File.expand_path('../../oa-core/', __FILE__) + +# Will automatically pull in this gem and all its +# dependencies specified in the gemspec +gem 'oa-basic', :path => File.expand_path("..", __FILE__) + +eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) diff --git a/oa-basic/Rakefile b/oa-basic/Rakefile index 4eba556..e8e6271 100644 --- a/oa-basic/Rakefile +++ b/oa-basic/Rakefile @@ -1,8 +1,6 @@ -ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) - require 'rubygems' require 'bundler' -Bundler.setup(:default, :development, :test, :oa_basic) +Bundler.setup require 'rake' require 'mg' diff --git a/oa-basic/dist/oa-basic-0.0.3/CHANGELOG.rdoc b/oa-basic/dist/oa-basic-0.0.3/CHANGELOG.rdoc new file mode 100644 index 0000000..718b0dc --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/CHANGELOG.rdoc @@ -0,0 +1,3 @@ +== 0.0.3 + +* First working release, Campfire and Basecamp support \ No newline at end of file diff --git a/oa-basic/dist/oa-basic-0.0.3/LICENSE.rdoc b/oa-basic/dist/oa-basic-0.0.3/LICENSE.rdoc new file mode 100644 index 0000000..e69de29 diff --git a/oa-basic/dist/oa-basic-0.0.3/README.rdoc b/oa-basic/dist/oa-basic-0.0.3/README.rdoc new file mode 100644 index 0000000..729b577 --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/README.rdoc @@ -0,0 +1,34 @@ += OmniAuth::Basic + +OmniAuth stratgies for APIs that have HTTP Basic authentication (such as Campfire and Basecamp). + +== Installation + +To get just HTTP Basic functionality: + + gem install oa-basic + +For the full auth suite: + + gem install omniauth + +== Stand-Alone Example + +Use the strategy as a middleware in your application: + + require 'omniauth/basic' + + use OmniAuth::Strategies::Campfire + +Then simply direct users to '/auth/campfire' to prompt them for their Campfire credentials. You may also pre-set the credentials by POSTing to the URL with appropriate parameters (in the case of Campfire and Basecamp, the parameters are subdomain, user, and password). + +== OmniAuth Builder + +If you want to allow multiple providers, use the OmniAuth Builder: + + require 'omniauth/basic' + + use OmniAuth::Builder do + provider :campfire + provider :basecamp + end diff --git a/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/basic.rb b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/basic.rb new file mode 100644 index 0000000..5b25006 --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/basic.rb @@ -0,0 +1,10 @@ +require 'omniauth/core' + +module OmniAuth + module Strategies + autoload :HttpBasic, 'omniauth/strategies/http_basic' + autoload :Basecamp, 'omniauth/strategies/basecamp' + autoload :Campfire, 'omniauth/strategies/campfire' + # autoload :Gowalla, 'omniauth/strategies/gowalla' + end +end diff --git a/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/basecamp.rb b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/basecamp.rb new file mode 100644 index 0000000..3db78e3 --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/basecamp.rb @@ -0,0 +1,55 @@ +require 'omniauth/basic' + +module OmniAuth + module Strategies + class Basecamp < HttpBasic + def initialize(app) + require 'json' + super(app, :basecamp, nil) + end + + def endpoint + "http://#{request.params['user']}:#{request.params['password']}@#{request.params['subdomain']}.basecamphq.com/me.xml" + end + + def perform_authentication(endpoint) + super(endpoint) rescue super(endpoint.sub('http','https')) + end + + def auth_hash + doc = Nokogiri::XML.parse(@response.body) + OmniAuth::Utils.deep_merge(super, { + 'uid' => doc.xpath('person/id').text, + 'user_info' => user_info(doc), + 'credentials' => { + 'token' => doc.xpath('person/token').text + } + }) + end + + def user_info(doc) + hash = { + 'nickname' => request.params['user'], + 'first_name' => doc.xpath('person/first-name').text, + 'last_name' => doc.xpath('person/last-name').text, + 'email' => doc.xpath('person/email-address').text, + 'image' => doc.xpath('person/avatar-url').text + } + + hash['name'] = [hash['first_name'], hash['last_name']].join(' ').strip + + hash.delete('image') if hash['image'].include?('missing/avatar.png') + + hash + end + + def get_credentials + OmniAuth::Form.build('Basecamp Authentication') do + text_field 'Subdomain', 'subdomain' + text_field 'Username', 'user' + password_field 'Password', 'password' + end.to_response + end + end + end +end diff --git a/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/campfire.rb b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/campfire.rb new file mode 100644 index 0000000..60b0cfd --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/campfire.rb @@ -0,0 +1,47 @@ +require 'omniauth/basic' + +module OmniAuth + module Strategies + class Campfire < HttpBasic + def initialize(app) + require 'json' + super(app, :campfire, nil) + end + + def endpoint + "http://#{request.params['user']}:#{request.params['password']}@#{request.params['subdomain']}.campfirenow.com/users/me.json" + end + + def perform_authentication(endpoint) + super(endpoint) rescue super(endpoint.sub('http','https')) + end + + def auth_hash + user_hash = JSON.parse(@response.body)['user'] + OmniAuth::Utils.deep_merge(super, { + 'uid' => user_hash['id'], + 'user_info' => user_info(user_hash), + 'credentials' => { + 'token' => user_hash['api_auth_token'] + } + }) + end + + def user_info(hash) + { + 'nickname' => request.params['user'], + 'name' => hash['name'], + 'email' => hash['email_address'] + } + end + + def get_credentials + OmniAuth::Form.build('Campfire Authentication') do + text_field 'Subdomain', 'subdomain' + text_field 'Username', 'user' + password_field 'Password', 'password' + end.to_response + end + end + end +end diff --git a/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/gowalla.rb b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/gowalla.rb new file mode 100644 index 0000000..bf85612 --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/gowalla.rb @@ -0,0 +1,19 @@ +# Gowalla's API isn't authenticated yet +# so this won't actually work at all it +# turns out. + +# require 'omniauth/basic' +# +# module OmniAuth +# module Strategies +# class Gowalla < OmniAuth::Strategies::HttpBasic #:nodoc: +# def initialize(app, api_key) +# super(app, :gowalla, nil, {'X-Gowalla-API-Key' => api_key, 'Accept' => 'application/json'}) +# end +# +# def endpoint +# "http://#{request[:username]}:#{request[:password]}@api.gowalla.com/users/#{request[:username]}" +# end +# end +# end +# end diff --git a/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/http_basic.rb b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/http_basic.rb new file mode 100644 index 0000000..d079d2a --- /dev/null +++ b/oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/http_basic.rb @@ -0,0 +1,56 @@ +require 'restclient' +require 'omniauth/basic' + +module OmniAuth + module Strategies + class HttpBasic + include OmniAuth::Strategy + + def initialize(app, name, endpoint, headers = {}) + super + @endpoint = endpoint + @request_headers = headers + end + + attr_reader :endpoint, :request_headers + + def request_phase + if env['REQUEST_METHOD'] == 'GET' + get_credentials + else + perform + end + end + + def title + name.split('_').map{|s| s.capitalize}.join(' ') + end + + def get_credentials + OmniAuth::Form.build(title) do + text_field 'Username', 'username' + password_field 'Password', 'password' + end.to_response + end + + def perform + @response = perform_authentication(endpoint) + request.POST['auth'] = auth_hash + @env['REQUEST_METHOD'] = 'GET' + @env['PATH_INFO'] = "#{OmniAuth.config.path_prefix}/#{name}/callback" + + @app.call(@env) + rescue RestClient::Request::Unauthorized + fail!(:invalid_credentials) + end + + def perform_authentication(uri, headers = request_headers) + RestClient.get(uri, headers) + end + + def callback_phase + fail!(:invalid_credentials) + end + end + end +end diff --git a/oa-basic/oa-basic.gemspec b/oa-basic/oa-basic.gemspec index 713d7bd..b2a30d5 100644 --- a/oa-basic/oa-basic.gemspec +++ b/oa-basic/oa-basic.gemspec @@ -1,5 +1,4 @@ require 'rubygems' -require 'bundler' version = File.open(File.dirname(__FILE__) + '/../VERSION', 'r').read.strip @@ -14,6 +13,10 @@ Gem::Specification.new do |gem| gem.files = Dir.glob("{lib}/**/*") + %w(README.rdoc LICENSE.rdoc CHANGELOG.rdoc) - gem.add_dependency 'oa-core', version - gem.add_bundler_dependencies(:default, :oa_basic, :development) + gem.add_dependency 'oa-core', version + gem.add_dependency 'rest-client', '~> 1.5.1' + gem.add_dependency 'json', '~> 1.4.3' + gem.add_dependency 'nokogiri', '~> 1.4.2' + + eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) end diff --git a/oa-core/Gemfile b/oa-core/Gemfile new file mode 100644 index 0000000..ae74972 --- /dev/null +++ b/oa-core/Gemfile @@ -0,0 +1,7 @@ +source "http://rubygems.org" + +# Will automatically pull in this gem and all its +# dependencies specified in the gemspec +gem 'oa-core', :path => File.expand_path("..", __FILE__) + +eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) diff --git a/oa-core/Rakefile b/oa-core/Rakefile index f5667b6..c7c6927 100644 --- a/oa-core/Rakefile +++ b/oa-core/Rakefile @@ -1,8 +1,6 @@ -ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) - require 'rubygems' require 'bundler' -Bundler.setup(:default, :development, :test) +Bundler.setup require 'rake' require 'mg' diff --git a/oa-core/oa-core.gemspec b/oa-core/oa-core.gemspec index 355b8a3..febf3c6 100644 --- a/oa-core/oa-core.gemspec +++ b/oa-core/oa-core.gemspec @@ -11,5 +11,7 @@ Gem::Specification.new do |gem| gem.files = Dir.glob("{lib}/**/*") + %w(LICENSE.rdoc CHANGELOG.rdoc) - gem.add_bundler_dependencies(:default, :oa_core, :development) + gem.add_dependency 'rack', '~> 1.1.0' + + eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) end diff --git a/oa-oauth/Gemfile b/oa-oauth/Gemfile new file mode 100644 index 0000000..cf38e11 --- /dev/null +++ b/oa-oauth/Gemfile @@ -0,0 +1,9 @@ +source "http://rubygems.org" + +gem 'oa-core', :path => File.expand_path('../../oa-core/', __FILE__) + +# Will automatically pull in this gem and all its +# dependencies specified in the gemspec +gem 'oa-oauth', :path => File.expand_path("..", __FILE__) + +eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) diff --git a/oa-oauth/Rakefile b/oa-oauth/Rakefile index 8392a38..ef9724a 100644 --- a/oa-oauth/Rakefile +++ b/oa-oauth/Rakefile @@ -1,8 +1,6 @@ -ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) - require 'rubygems' require 'bundler' -Bundler.setup(:default, :development, :test, :oa_oauth) +Bundler.setup require 'rake' require 'mg' diff --git a/oa-oauth/oa-oauth.gemspec b/oa-oauth/oa-oauth.gemspec index a638062..807ae8e 100644 --- a/oa-oauth/oa-oauth.gemspec +++ b/oa-oauth/oa-oauth.gemspec @@ -1,3 +1,5 @@ +require 'rubygems' + version = File.open(File.dirname(__FILE__) + '/../VERSION', 'r').read.strip Gem::Specification.new do |gem| @@ -11,6 +13,12 @@ Gem::Specification.new do |gem| gem.files = Dir.glob("{lib}/**/*") + %w(README.rdoc LICENSE.rdoc CHANGELOG.rdoc) - gem.add_dependency 'oa-core', version - gem.add_bundler_dependencies(:default, :oa_oauth, :development) + gem.add_dependency 'oa-core', version + gem.add_dependency 'rack', '~> 1.1.0' + gem.add_dependency 'json', '~> 1.4.3' + gem.add_dependency 'nokogiri', '~> 1.4.2' + gem.add_dependency 'oauth', '~> 0.4.0' + gem.add_dependency 'oauth2', '~> 0.0.8' + + eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) end diff --git a/oa-openid/Gemfile b/oa-openid/Gemfile new file mode 100644 index 0000000..9e3ee5d --- /dev/null +++ b/oa-openid/Gemfile @@ -0,0 +1,9 @@ +source "http://rubygems.org" + +gem 'oa-core', :path => File.expand_path('../../oa-core/', __FILE__) + +# Will automatically pull in this gem and all its +# dependencies specified in the gemspec +gem 'oa-openid', :path => File.expand_path("..", __FILE__) + +eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) diff --git a/oa-openid/Rakefile b/oa-openid/Rakefile index cba0298..f845e1b 100644 --- a/oa-openid/Rakefile +++ b/oa-openid/Rakefile @@ -1,8 +1,6 @@ -ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) - require 'rubygems' require 'bundler' -Bundler.setup(:default, :development, :test, :oa_openid) +Bundler.setup require 'rake' require 'mg' diff --git a/oa-openid/oa-openid.gemspec b/oa-openid/oa-openid.gemspec index d5b7db0..f04014e 100644 --- a/oa-openid/oa-openid.gemspec +++ b/oa-openid/oa-openid.gemspec @@ -11,6 +11,8 @@ Gem::Specification.new do |gem| gem.files = Dir.glob("{lib}/**/*") + %w(README.rdoc LICENSE.rdoc CHANGELOG.rdoc) - gem.add_dependency 'oa-core', version - gem.add_bundler_dependencies(:default, :oa_openid, :development) + gem.add_dependency 'oa-core', version + gem.add_dependency 'rack-openid', '~> 1.0.3' + + eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) end diff --git a/omniauth/Gemfile b/omniauth/Gemfile new file mode 100644 index 0000000..8cd28d8 --- /dev/null +++ b/omniauth/Gemfile @@ -0,0 +1,12 @@ +source "http://rubygems.org" + +gem 'oa-core', :path => File.expand_path('../../oa-core/', __FILE__) +gem 'oa-basic', :path => File.expand_path('../../oa-basic/', __FILE__) +gem 'oa-oauth', :path => File.expand_path('../../oa-oauth/', __FILE__) +gem 'oa-openid', :path => File.expand_path('../../oa-openid/', __FILE__) + +# Will automatically pull in this gem and all its +# dependencies specified in the gemspec +gem 'omniauth', :path => File.expand_path("..", __FILE__) + +eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) diff --git a/omniauth/Rakefile b/omniauth/Rakefile index 7a3f56f..55b96b5 100644 --- a/omniauth/Rakefile +++ b/omniauth/Rakefile @@ -1,6 +1,6 @@ require 'rubygems' require 'bundler' -Bundler.setup(:default, :development, :test) +Bundler.setup require 'rake' require 'mg' diff --git a/omniauth/omniauth.gemspec b/omniauth/omniauth.gemspec index 300ecec..fbc9440 100644 --- a/omniauth/omniauth.gemspec +++ b/omniauth/omniauth.gemspec @@ -14,6 +14,6 @@ Gem::Specification.new do |gem| %w(oa-core oa-oauth oa-basic oa-openid).each do |subgem| gem.add_dependency subgem, version end - - gem.add_bundler_dependencies(:development) + + eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) end \ No newline at end of file