Skip to content

Commit

Permalink
Bundler's add_bundler_dependencies is considered harmful and being de…
Browse files Browse the repository at this point in the history
…precated; changed from Gemfile -> .gemspec dependencies to the reverse.
  • Loading branch information
jamesarosen committed Jun 13, 2010
1 parent 67d752a commit f4919a1
Show file tree
Hide file tree
Showing 26 changed files with 322 additions and 57 deletions.
30 changes: 0 additions & 30 deletions Gemfile

This file was deleted.

6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require 'rubygems'
require 'bundler'
Bundler.setup(:development)
require 'rake'
require 'term/ansicolor'

Expand Down Expand Up @@ -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'
Expand Down
20 changes: 20 additions & 0 deletions development_dependencies.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions oa-basic/Gemfile
Original file line number Diff line number Diff line change
@@ -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'))
4 changes: 1 addition & 3 deletions oa-basic/Rakefile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 3 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
== 0.0.3

* First working release, Campfire and Basecamp support
Empty file.
34 changes: 34 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/README.rdoc
Original file line number Diff line number Diff line change
@@ -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 <tt>subdomain</tt>, <tt>user</tt>, and <tt>password</tt>).

== 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
10 changes: 10 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/lib/omniauth/basic.rb
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/basecamp.rb
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/campfire.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/gowalla.rb
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/http_basic.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions oa-basic/oa-basic.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rubygems'
require 'bundler'

version = File.open(File.dirname(__FILE__) + '/../VERSION', 'r').read.strip

Expand All @@ -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
7 changes: 7 additions & 0 deletions oa-core/Gemfile
Original file line number Diff line number Diff line change
@@ -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'))
4 changes: 1 addition & 3 deletions oa-core/Rakefile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 3 additions & 1 deletion oa-core/oa-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions oa-oauth/Gemfile
Original file line number Diff line number Diff line change
@@ -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'))
4 changes: 1 addition & 3 deletions oa-oauth/Rakefile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
Loading

0 comments on commit f4919a1

Please sign in to comment.