1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Bundler's add_bundler_dependencies is considered harmful and being deprecated; changed from Gemfile -> .gemspec dependencies to the reverse.

This commit is contained in:
James A. Rosen 2010-06-13 16:36:59 -04:00
parent 67d752ad0f
commit f4919a113a
26 changed files with 322 additions and 57 deletions

30
Gemfile
View file

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

View file

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

View file

@ -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
oa-basic/Gemfile Normal file
View file

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

View file

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

View file

@ -0,0 +1,3 @@
== 0.0.3
* First working release, Campfire and Basecamp support

View file

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

7
oa-core/Gemfile Normal file
View file

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

View file

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

View file

@ -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
oa-oauth/Gemfile Normal file
View file

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

View file

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

View file

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

9
oa-openid/Gemfile Normal file
View file

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

View file

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

View file

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

12
omniauth/Gemfile Normal file
View file

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

View file

@ -1,6 +1,6 @@
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :development, :test)
Bundler.setup
require 'rake'
require 'mg'

View file

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