Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: intridea/omniauth
base: v0.1.3
...
head fork: intridea/omniauth
compare: v0.1.4
Checking mergeability… Don't worry, you can still create the pull request.
  • 10 commits
  • 18 files changed
  • 0 commit comments
  • 3 contributors
View
2  .gitignore
@@ -28,3 +28,5 @@ oa-live
*.gem
.bundle
.project
+
+Gemfile.lock
View
4 README.markdown
@@ -35,10 +35,10 @@ OmniAuth is a collection of Rack middleware. To use a single strategy, you simpl
require 'oa-oauth'
use OmniAuth::Strategies::Twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
-Now to initiate authentication you merely need to redirect the user to `/auth/twitter` via a link or other means. Once the user has authenticated to Twitter, they will be redirected to `/auth/twitter/callback`. You should build an endpoint that handles this URL, at which point you will will have access to the authentication information through the `rack.auth` parameter of the Rack environment. For example, in Sinatra you would do something like this:
+Now to initiate authentication you merely need to redirect the user to `/auth/twitter` via a link or other means. Once the user has authenticated to Twitter, they will be redirected to `/auth/twitter/callback`. You should build an endpoint that handles this URL, at which point you will will have access to the authentication information through the `omniauth.auth` parameter of the Rack environment. For example, in Sinatra you would do something like this:
get '/auth/twitter/callback' do
- auth_hash = request.env['rack.auth']
+ auth_hash = request.env['omniauth.auth']
end
The hash in question will look something like this:
View
2  VERSION
@@ -1 +1 @@
-0.1.3
+0.1.4
View
50 oa-basic/Gemfile.lock
@@ -1,50 +0,0 @@
-PATH
- remote: .
- specs:
- oa-basic (0.1.2)
- multi_json (~> 0.0.2)
- nokogiri (~> 1.4.2)
- oa-core (= 0.1.2)
- rest-client (~> 1.6.0)
-
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-core
- specs:
- oa-core (0.1.2)
- rack (~> 1.1)
-
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.0)
- crack (0.1.8)
- json (1.4.3)
- mg (0.0.8)
- rake
- mime-types (1.16)
- multi_json (0.0.4)
- nokogiri (1.4.3.1)
- rack (1.2.1)
- rack-test (0.5.4)
- rack (>= 1.0)
- rake (0.8.7)
- rest-client (1.6.0)
- mime-types (>= 1.16)
- rspec (1.3.0)
- webmock (1.3.4)
- addressable (>= 2.1.1)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- json (~> 1.4.3)
- mg (~> 0.0.8)
- oa-basic!
- oa-core!
- rack
- rack-test (~> 0.5.4)
- rake
- rspec (~> 1.3.0)
- webmock (~> 1.3.4)
View
35 oa-core/Gemfile.lock
@@ -1,35 +0,0 @@
-PATH
- remote: .
- specs:
- oa-core (0.1.2)
- rack (~> 1.1)
-
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.0)
- crack (0.1.8)
- json (1.4.3)
- mg (0.0.8)
- rake
- rack (1.2.1)
- rack-test (0.5.4)
- rack (>= 1.0)
- rake (0.8.7)
- rspec (1.3.0)
- webmock (1.3.4)
- addressable (>= 2.1.1)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- json (~> 1.4.3)
- mg (~> 0.0.8)
- oa-core!
- rack
- rack-test (~> 0.5.4)
- rake
- rspec (~> 1.3.0)
- webmock (~> 1.3.4)
View
40 oa-core/lib/omniauth/core.rb
@@ -3,35 +3,35 @@
require 'omniauth/form'
module OmniAuth
-
+
autoload :Builder, 'omniauth/builder'
autoload :Strategy, 'omniauth/strategy'
autoload :Test, 'omniauth/test'
-
+
module Strategies
autoload :Password, 'omniauth/strategies/password'
end
-
+
class Configuration
include Singleton
-
+
@@defaults = {
:path_prefix => '/auth',
:on_failure => Proc.new do |env, message_key|
new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
- [302, {'Location' => "#{new_path}"}, []]
+ [302, {'Location' => "#{new_path}", 'Content-Type'=> 'text/html'}, []]
end,
:form_css => Form::DEFAULT_CSS
}
-
+
def self.defaults
@@defaults
end
-
+
def initialize
@@defaults.each_pair{|k,v| self.send("#{k}=",v)}
end
-
+
def on_failure(&block)
if block_given?
@on_failure = block
@@ -39,19 +39,19 @@ def on_failure(&block)
@on_failure
end
end
-
+
attr_writer :on_failure
attr_accessor :path_prefix, :form_css
end
-
+
def self.config
Configuration.instance
end
-
+
def self.configure
yield config
end
-
+
module Utils
CAMELIZE_SPECIAL = {
'oauth' => 'OAuth',
@@ -60,31 +60,31 @@ module Utils
'open_id' => 'OpenID',
'github' => 'GitHub'
}
-
+
module_function
-
+
def form_css
"<style type='text/css'>#{OmniAuth.config.form_css}</style>"
end
-
+
def deep_merge(hash, other_hash)
target = hash.dup
-
+
other_hash.keys.each do |key|
if other_hash[key].is_a? ::Hash and hash[key].is_a? ::Hash
target[key] = deep_merge(target[key],other_hash[key])
next
end
-
+
target[key] = other_hash[key]
end
-
+
target
end
-
+
def camelize(word, first_letter_in_uppercase = true)
return CAMELIZE_SPECIAL[word.to_s] if CAMELIZE_SPECIAL[word.to_s]
-
+
if first_letter_in_uppercase
word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
else
View
48 oa-enterprise/Gemfile.lock
@@ -1,48 +0,0 @@
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-core
- specs:
- oa-core (0.1.2)
- rack (~> 1.1)
-
-PATH
- remote: .
- specs:
- oa-enterprise (0.1.2)
- net-ldap (~> 0.1.1)
- nokogiri (~> 1.4.2)
- oa-core (= 0.1.2)
- rubyntlm (~> 0.1.1)
-
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.0)
- crack (0.1.8)
- json (1.4.3)
- mg (0.0.8)
- rake
- net-ldap (0.1.1)
- nokogiri (1.4.3.1)
- rack (1.1.0)
- rack-test (0.5.4)
- rack (>= 1.0)
- rake (0.8.7)
- rspec (1.3.0)
- rubyntlm (0.1.1)
- webmock (1.3.4)
- addressable (>= 2.1.1)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- json (~> 1.4.3)
- mg (~> 0.0.8)
- oa-core!
- oa-enterprise!
- rack
- rack-test (~> 0.5.4)
- rake
- rspec (~> 1.3.0)
- webmock (~> 1.3.4)
View
55 oa-oauth/Gemfile.lock
@@ -1,55 +0,0 @@
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-core
- specs:
- oa-core (0.1.2)
- rack (~> 1.1)
-
-PATH
- remote: .
- specs:
- oa-oauth (0.1.2)
- multi_json (~> 0.0.2)
- nokogiri (~> 1.4.2)
- oa-core (= 0.1.2)
- oauth (~> 0.4.0)
- oauth2 (~> 0.0.10)
-
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.0)
- crack (0.1.8)
- faraday (0.4.6)
- addressable (>= 2.1.1)
- rack (>= 1.0.1)
- json (1.4.3)
- mg (0.0.8)
- rake
- multi_json (0.0.4)
- nokogiri (1.4.3.1)
- oauth (0.4.3)
- oauth2 (0.0.13)
- faraday (~> 0.4.1)
- multi_json (>= 0.0.4)
- rack (1.2.1)
- rack-test (0.5.4)
- rack (>= 1.0)
- rake (0.8.7)
- rspec (1.3.0)
- webmock (1.3.4)
- addressable (>= 2.1.1)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- json (~> 1.4.3)
- mg (~> 0.0.8)
- oa-core!
- oa-oauth!
- rack
- rack-test (~> 0.5.4)
- rake
- rspec (~> 1.3.0)
- webmock (~> 1.3.4)
View
1  oa-oauth/lib/omniauth/oauth.rb
@@ -12,5 +12,6 @@ module Strategies
autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
autoload :Foursquare, 'omniauth/strategies/foursquare'
autoload :Gowalla, 'omniauth/strategies/gowalla'
+ autoload :Identica, 'omniauth/strategies/identica'
end
end
View
4 oa-oauth/lib/omniauth/strategies/facebook.rb
@@ -24,9 +24,9 @@ def user_data
@data ||= MultiJson.decode(@access_token.get('/me'))
end
- def request_phase(options = {})
+ def request_phase
options[:scope] ||= "email,offline_access"
- super(options)
+ super
end
def user_info
View
4 oa-oauth/lib/omniauth/strategies/gowalla.rb
@@ -26,9 +26,9 @@ def user_data
@data ||= MultiJson.decode(@access_token.get("/users/me.json"))
end
- def request_phase(options = {})
+ def request_phase
options[:scope] ||= "email,offline_access"
- super(options)
+ super
end
def user_info
View
49 oa-oauth/lib/omniauth/strategies/identica.rb
@@ -0,0 +1,49 @@
+require 'omniauth/oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ #
+ # Authenticate to Identica via OAuth and retrieve basic
+ # user information.
+ #
+ # Usage:
+ #
+ # use OmniAuth::Strategies::Identica, 'consumerkey', 'consumersecret'
+ #
+ class Identica < OmniAuth::Strategies::OAuth
+ def initialize(app, consumer_key, consumer_secret)
+ super(app, :identica, consumer_key, consumer_secret,
+ :site => 'http://identi.ca',
+ :request_token_path => "/api/oauth/request_token",
+ :access_token_path => "/api/oauth/access_token",
+ :authorize_path => "/api/oauth/authorize")
+ end
+
+ def auth_hash
+ OmniAuth::Utils.deep_merge(super, {
+ 'uid' => @access_token.params[:user_id],
+ 'user_info' => user_info,
+ 'extra' => {'user_hash' => user_hash}
+ })
+ end
+
+ def user_info
+ user_hash = self.user_hash
+
+ {
+ 'nickname' => user_hash['screen_name'],
+ 'name' => user_hash['name'],
+ 'location' => user_hash['location'],
+ 'image' => user_hash['profile_image_url'],
+ 'description' => user_hash['description'],
+ 'urls' => {'Website' => user_hash['url']}
+ }
+ end
+
+ def user_hash
+ @user_hash ||= MultiJson.decode(@access_token.get('/api/account/verify_credentials.json').body)
+ end
+ end
+ end
+end
View
28 oa-oauth/lib/omniauth/strategies/oauth2.rb
@@ -8,25 +8,39 @@ module Strategies
class OAuth2
include OmniAuth::Strategy
+ attr_accessor :options, :client
+
+ class CallbackError < StandardError
+ attr_accessor :error, :error_reason, :error_uri
+
+ def initialize(error, error_reason=nil, error_uri=nil)
+ self.error = error
+ self.error_reason = error_reason
+ self.error_uri = error_uri
+ end
+ end
+
def initialize(app, name, client_id, client_secret, options = {})
super(app, name)
- @options = options
- @client = ::OAuth2::Client.new(client_id, client_secret, options)
+ self.options = options
+ self.client = ::OAuth2::Client.new(client_id, client_secret, options)
end
protected
-
- attr_accessor :client
-
- def request_phase(options = {})
+
+ def request_phase
redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
end
def callback_phase
+ if request.params['error']
+ raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
+ end
+
verifier = request.params['code']
@access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
super
- rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied => e
+ rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
fail!(:invalid_credentials, e)
end
View
13 oa-oauth/spec/omniauth/strategies/identica_spec.rb
@@ -0,0 +1,13 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe 'OmniAuth::Strategies::Identica' do
+
+ it 'should subclass Identica' do
+ OmniAuth::Strategies::Identica.should < OmniAuth::Strategies::OAuth
+ end
+
+ it 'should initialize with just consumer key and secret' do
+ lambda{OmniAuth::Strategies::Identica.new({},'abc','def')}.should_not raise_error
+ end
+
+end
View
51 oa-openid/Gemfile.lock
@@ -1,51 +0,0 @@
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-core
- specs:
- oa-core (0.1.2)
- rack (~> 1.1)
-
-PATH
- remote: .
- specs:
- oa-openid (0.1.2)
- oa-core (= 0.1.2)
- rack-openid (~> 1.1.1)
- ruby-openid-apps-discovery
-
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.0)
- crack (0.1.8)
- json (1.4.3)
- mg (0.0.8)
- rake
- rack (1.2.1)
- rack-openid (1.1.1)
- rack (>= 0.4)
- ruby-openid (>= 2.0.3)
- rack-test (0.5.4)
- rack (>= 1.0)
- rake (0.8.7)
- rspec (1.3.0)
- ruby-openid (2.1.8)
- ruby-openid-apps-discovery (1.2.0)
- ruby-openid (>= 2.1.7)
- webmock (1.3.4)
- addressable (>= 2.1.1)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- json (~> 1.4.3)
- mg (~> 0.0.8)
- oa-core!
- oa-openid!
- rack
- rack-test (~> 0.5.4)
- rake
- rspec (~> 1.3.0)
- ruby-openid-apps-discovery
- webmock (~> 1.3.4)
View
32 oa-openid/lib/omniauth/openid/gapps.rb
@@ -0,0 +1,32 @@
+require 'openid/consumer'
+require 'gapps_openid'
+
+module OpenID
+ # Because gapps_openid changes the discovery order
+ # (looking first for Google Apps, then anything else),
+ # we need to monkeypatch it to make it play nicely
+ # with others.
+ def self.discover(uri)
+ discovered = self.default_discover(uri)
+
+ if discovered.last.empty?
+ info = discover_google_apps(uri)
+ return info if info
+ end
+
+ return discovered
+ rescue OpenID::DiscoveryFailure => e
+ info = discover_google_apps(uri)
+
+ if info.nil?
+ raise e
+ else
+ return info
+ end
+ end
+
+ def self.discover_google_apps(uri)
+ discovery = GoogleDiscovery.new
+ discovery.perform_discovery(uri)
+ end
+end
View
6 oa-openid/lib/omniauth/strategies/open_id.rb
@@ -1,5 +1,5 @@
require 'rack/openid'
-require 'gapps_openid'
+require 'omniauth/openid/gapps'
require 'omniauth/openid'
module OmniAuth
@@ -24,7 +24,7 @@ class OpenID
}
def initialize(app, store = nil, options = {})
- super(app, options[:name] || :open_id)
+ super(app, options.delete(:name) || :open_id)
@options = options
@options[:required] ||= [AX[:email], AX[:first_name], AX[:last_name], 'email', 'fullname']
@options[:optional] ||= [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname']
@@ -47,7 +47,7 @@ def callback_url
end
def identifier
- request[IDENTIFIER_URL_PARAMETER]
+ options[:identifier] || request[IDENTIFIER_URL_PARAMETER]
end
def request_phase
View
106 omniauth/Gemfile.lock
@@ -1,106 +0,0 @@
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-basic
- specs:
- oa-basic (0.1.2)
- multi_json (~> 0.0.2)
- nokogiri (~> 1.4.2)
- oa-core (= 0.1.2)
- rest-client (~> 1.6.0)
-
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-core
- specs:
- oa-core (0.1.2)
- rack (~> 1.1)
-
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-enterprise
- specs:
- oa-enterprise (0.1.2)
- net-ldap (~> 0.1.1)
- nokogiri (~> 1.4.2)
- oa-core (= 0.1.2)
- rubyntlm (~> 0.1.1)
-
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-oauth
- specs:
- oa-oauth (0.1.2)
- multi_json (~> 0.0.2)
- nokogiri (~> 1.4.2)
- oa-core (= 0.1.2)
- oauth (~> 0.4.0)
- oauth2 (~> 0.0.10)
-
-PATH
- remote: /Users/mbleigh/gems/omniauth/oa-openid
- specs:
- oa-openid (0.1.2)
- oa-core (= 0.1.2)
- rack-openid (~> 1.1.1)
- ruby-openid-apps-discovery
-
-PATH
- remote: .
- specs:
- omniauth (0.1.2)
- oa-basic (= 0.1.2)
- oa-core (= 0.1.2)
- oa-enterprise (= 0.1.2)
- oa-oauth (= 0.1.2)
- oa-openid (= 0.1.2)
-
-GEM
- remote: http://rubygems.org/
- specs:
- addressable (2.2.0)
- crack (0.1.8)
- faraday (0.4.6)
- addressable (>= 2.1.1)
- rack (>= 1.0.1)
- json (1.4.3)
- mg (0.0.8)
- rake
- mime-types (1.16)
- multi_json (0.0.4)
- net-ldap (0.1.1)
- nokogiri (1.4.3.1)
- oauth (0.4.3)
- oauth2 (0.0.13)
- faraday (~> 0.4.1)
- multi_json (>= 0.0.4)
- rack (1.2.1)
- rack-openid (1.1.1)
- rack (>= 0.4)
- ruby-openid (>= 2.0.3)
- rack-test (0.5.4)
- rack (>= 1.0)
- rake (0.8.7)
- rest-client (1.6.0)
- mime-types (>= 1.16)
- rspec (1.3.0)
- ruby-openid (2.1.8)
- ruby-openid-apps-discovery (1.2.0)
- ruby-openid (>= 2.1.7)
- rubyntlm (0.1.1)
- webmock (1.3.4)
- addressable (>= 2.1.1)
- crack (>= 0.1.7)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- json (~> 1.4.3)
- mg (~> 0.0.8)
- oa-basic!
- oa-core!
- oa-enterprise!
- oa-oauth!
- oa-openid!
- omniauth!
- rack
- rack-test (~> 0.5.4)
- rake
- rspec (~> 1.3.0)
- webmock (~> 1.3.4)

No commit comments for this range

Something went wrong with that request. Please try again.