forked from omniauth/omniauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bundler's add_bundler_dependencies is considered harmful and being de…
…precated; changed from Gemfile -> .gemspec dependencies to the reverse.
- Loading branch information
1 parent
67d752a
commit f4919a1
Showing
26 changed files
with
322 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/basecamp.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/campfire.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/gowalla.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
oa-basic/dist/oa-basic-0.0.3/lib/omniauth/strategies/http_basic.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.