warden_omniauth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +80 -0
- data/README.markdown +93 -0
- data/Rakefile +18 -0
- data/examples/twitter/config.ru +42 -0
- data/lib/warden_omniauth.rb +150 -0
- data/lib/warden_omniauth/version.rb +3 -0
- data/test/test_helper.rb +42 -0
- data/test/test_warden_omniauth.rb +131 -0
- data/warden_omniauth.gemspec +25 -0
- metadata +124 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
warden_omniauth (0.0.1)
|
5
|
+
omniauth
|
6
|
+
warden (>= 0.9)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.2.0)
|
12
|
+
faraday (0.4.6)
|
13
|
+
addressable (>= 2.1.1)
|
14
|
+
rack (>= 1.0.1)
|
15
|
+
mime-types (1.16)
|
16
|
+
multi_json (0.0.4)
|
17
|
+
nanotest (0.9.4.1)
|
18
|
+
nanotest_extensions (0.6.3)
|
19
|
+
net-ldap (0.1.1)
|
20
|
+
nokogiri (1.4.3.1)
|
21
|
+
oa-basic (0.1.1)
|
22
|
+
multi_json (~> 0.0.2)
|
23
|
+
nokogiri (~> 1.4.2)
|
24
|
+
oa-core (= 0.1.1)
|
25
|
+
rest-client (~> 1.6.0)
|
26
|
+
oa-core (0.1.1)
|
27
|
+
rack (~> 1.1)
|
28
|
+
oa-enterprise (0.1.1)
|
29
|
+
net-ldap (~> 0.1.1)
|
30
|
+
nokogiri (~> 1.4.2)
|
31
|
+
oa-core (= 0.1.1)
|
32
|
+
rubyntlm (~> 0.1.1)
|
33
|
+
oa-oauth (0.1.1)
|
34
|
+
multi_json (~> 0.0.2)
|
35
|
+
nokogiri (~> 1.4.2)
|
36
|
+
oa-core (= 0.1.1)
|
37
|
+
oauth (~> 0.4.0)
|
38
|
+
oauth2 (~> 0.0.10)
|
39
|
+
oa-openid (0.1.1)
|
40
|
+
oa-core (= 0.1.1)
|
41
|
+
rack-openid (~> 1.1.1)
|
42
|
+
ruby-openid-apps-discovery
|
43
|
+
oauth (0.4.3)
|
44
|
+
oauth2 (0.0.13)
|
45
|
+
faraday (~> 0.4.1)
|
46
|
+
multi_json (>= 0.0.4)
|
47
|
+
omniauth (0.1.1)
|
48
|
+
oa-basic (= 0.1.1)
|
49
|
+
oa-core (= 0.1.1)
|
50
|
+
oa-enterprise (= 0.1.1)
|
51
|
+
oa-oauth (= 0.1.1)
|
52
|
+
oa-openid (= 0.1.1)
|
53
|
+
rack (1.2.1)
|
54
|
+
rack-openid (1.1.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
ruby-openid (>= 2.0.3)
|
57
|
+
rack-test (0.5.6)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rake (0.8.7)
|
60
|
+
rest-client (1.6.1)
|
61
|
+
mime-types (>= 1.16)
|
62
|
+
ruby-openid (2.1.8)
|
63
|
+
ruby-openid-apps-discovery (1.2.0)
|
64
|
+
ruby-openid (>= 2.1.7)
|
65
|
+
rubyntlm (0.1.1)
|
66
|
+
warden (0.10.7)
|
67
|
+
rack (>= 1.0.0)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
ruby
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
bundler (>= 1.0.0)
|
74
|
+
nanotest
|
75
|
+
nanotest_extensions
|
76
|
+
omniauth
|
77
|
+
rack-test
|
78
|
+
rake
|
79
|
+
warden (>= 0.9)
|
80
|
+
warden_omniauth!
|
data/README.markdown
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Warden OmniAuth
|
2
|
+
|
3
|
+
OmniAuth is a pretty aweome library. If you haven't checked it out yet, you really should. This is a simple wrapper for OmniAuth so that it can be used from a warden project. It sorts storing the user into the sesion, redirection on callbacks etc.
|
4
|
+
|
5
|
+
With it, you can make use of any of the [OmniAuth](http://github.com/intridea/omniauth) authentication library. This provides some great external authentication mechanisms.
|
6
|
+
|
7
|
+
Warden provides a consistent interface for projects, engines, and arbitrary rack applicaitons. The benefit of warden, is that you do no need to know what the host application considers authentication to use it. It also provides a way to store the user in the session etc.
|
8
|
+
|
9
|
+
By using WardenOmniAuth, you can make use of any of the OmniAuth authentication mechanisms in your host application, and any rack middleware or applications can just continue using warden without change.
|
10
|
+
|
11
|
+
This is also usable in the [Devise](http://github.com/plataformatec/devise) Rails Engine
|
12
|
+
## Usage (Rack)
|
13
|
+
|
14
|
+
<pre><code>use OmniAuth::Builer do
|
15
|
+
# setup omniauth
|
16
|
+
end
|
17
|
+
|
18
|
+
use Warden::Manager do |config|
|
19
|
+
# setup warden configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
use WardenOmniAuth do |config|
|
23
|
+
config.redirect\_after\_callback = "/redirect/path" # default "/"
|
24
|
+
end
|
25
|
+
|
26
|
+
run MyApp
|
27
|
+
</code></pre>
|
28
|
+
|
29
|
+
## Usage (Devise)
|
30
|
+
|
31
|
+
<pre><code># config/initializer.rb
|
32
|
+
Devise.setup do |config|
|
33
|
+
config.warden do |manager|
|
34
|
+
[:omni\_twitter, :omni\_facebook, :omni\_github].each do |strategy|
|
35
|
+
manager.default\_strategies(:scope => :user).unshift strategy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
</code></pre>
|
39
|
+
|
40
|
+
This will add the stratgeies to the normal devise user login for github, then facebook, then twitter.
|
41
|
+
|
42
|
+
# Dealing with callbacks
|
43
|
+
|
44
|
+
OmniAuth uses callbacks to give you the user object, WardenOmniAuth provides a way to store this into the session
|
45
|
+
|
46
|
+
By default, it grabs just _user\\info_, _uid_, _credentials_, _provider_ as a hash in the session.
|
47
|
+
|
48
|
+
If you want to customise this you can do:
|
49
|
+
|
50
|
+
<pre><code>
|
51
|
+
WardenOmniAuth.on\_callback do |user|
|
52
|
+
# all callbacks will go here by default
|
53
|
+
end
|
54
|
+
</code></pre>
|
55
|
+
|
56
|
+
Whatever you return from the block is the user that's made available in warden.
|
57
|
+
|
58
|
+
## Dealing with each kind of callback
|
59
|
+
|
60
|
+
<pre><code>
|
61
|
+
use WardenOmniAuth do |config|
|
62
|
+
Warden::Strategies[:omni\_twitter] do |user|
|
63
|
+
# do stuff to get a user and return it from the block
|
64
|
+
end
|
65
|
+
|
66
|
+
Warden::Strategies[:omni\_facebook] do |user|
|
67
|
+
# do stuff to get a user for a facebook user
|
68
|
+
end
|
69
|
+
end
|
70
|
+
</code></pre>
|
71
|
+
|
72
|
+
This will use a specific callback to get the user, or fallback if nothing specific has been defined.
|
73
|
+
|
74
|
+
|
75
|
+
# Why? (Gimmie an alternative)
|
76
|
+
|
77
|
+
Because I wanted to see how it would be to integrate this strategy into warden. Turns out to be pretty simple, but there's nothing stopping you from just providing a callback directly for OmniAuth.
|
78
|
+
|
79
|
+
However, it's just as simple to provide endpoints for OmniAuth callbacks. (Assuming you already have warden setup in your app)
|
80
|
+
|
81
|
+
Example:
|
82
|
+
|
83
|
+
<pre><code>
|
84
|
+
get "/auth/twitter/callback" do
|
85
|
+
user = munge_user_from_env(env['rack.auth'])
|
86
|
+
warden.set_user user
|
87
|
+
redirect "/somewhere"
|
88
|
+
end
|
89
|
+
</code></pre>
|
90
|
+
|
91
|
+
You can see from this small snippet, that you don't really need this library, just define your callbacks to set the user and you're done.
|
92
|
+
|
93
|
+
Rack is a beutiful thing!
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
# --------------------------------------------------
|
5
|
+
# Tests
|
6
|
+
# --------------------------------------------------
|
7
|
+
namespace(:test) do
|
8
|
+
|
9
|
+
desc "run framework compatibility tests"
|
10
|
+
task(:all) do
|
11
|
+
Dir['test/test_*.rb'].each do |path|
|
12
|
+
cmd = "ruby -rubygems -I.:lib -I.:test/test_helper.rb #{path}"
|
13
|
+
puts(cmd) if ENV['VERBOSE']
|
14
|
+
system(cmd)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
|
2
|
+
|
3
|
+
require 'warden_omniauth'
|
4
|
+
|
5
|
+
Warden::Manager.serialize_into_session do |user|
|
6
|
+
user
|
7
|
+
end
|
8
|
+
|
9
|
+
Warden::Manager.serialize_from_session do |user|
|
10
|
+
user
|
11
|
+
end
|
12
|
+
|
13
|
+
app = lambda do |e|
|
14
|
+
request = Rack::Request.new(e)
|
15
|
+
if request.path =~ /logout/
|
16
|
+
e['warden'].logout
|
17
|
+
r = Rack::Response.new
|
18
|
+
r.redirect("/")
|
19
|
+
r.finish
|
20
|
+
else
|
21
|
+
e['warden'].authenticate!
|
22
|
+
Rack::Response.new(e['warden'].user.inspect).finish
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
failure = lambda{|e| Rack::Resposne.new("Can't login", 401).finish }
|
27
|
+
|
28
|
+
use Rack::Session::Cookie
|
29
|
+
|
30
|
+
use Warden::Manager do |config|
|
31
|
+
config.failure_app = failure
|
32
|
+
config.default_strategies :omni_twitter
|
33
|
+
end
|
34
|
+
|
35
|
+
use OmniAuth::Strategies::Twitter, key, sekrit
|
36
|
+
use WardenOmniAuth do |config|
|
37
|
+
config.redirect_after_callback = "/foo/bar"
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
run app
|
42
|
+
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'warden'
|
2
|
+
require 'omniauth'
|
3
|
+
|
4
|
+
class WardenOmniAuth
|
5
|
+
DEFAULT_CALLBACK = lambda do |user|
|
6
|
+
u = {}
|
7
|
+
u[:user_info] = user['user_info']
|
8
|
+
u[:uid] = user['uid']
|
9
|
+
u[:credentials] = user['credentials']
|
10
|
+
u[:provider] = user['provider']
|
11
|
+
u
|
12
|
+
end
|
13
|
+
|
14
|
+
SCOPE_KEY = 'warden_omni_auth.scope'
|
15
|
+
SESSION_KEY = 'rack.session'
|
16
|
+
|
17
|
+
# Setup a callback to transform the user from the omni user hash
|
18
|
+
# to what you want warden to store as the user object
|
19
|
+
# @example
|
20
|
+
# WardenOmniAuth.on_callback do |omni_user|
|
21
|
+
# User.find_or_create_by_uid(omni_user['uid'])
|
22
|
+
# end
|
23
|
+
def self.on_callback(&blk)
|
24
|
+
@on_callback = blk if blk
|
25
|
+
@on_callback || DEFAULT_CALLBACK
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create a warden strategy to wrap an OmniAuth strategy
|
29
|
+
# @param name - The name of the omniauth strategy
|
30
|
+
# @example
|
31
|
+
# WardenOmniAuth.setup_strategies(:twitter, :facebook)
|
32
|
+
def self.setup_strategies(*names)
|
33
|
+
names.map do |name|
|
34
|
+
full_name = :"omni_#{name}"
|
35
|
+
unless Warden::Strategies[full_name]
|
36
|
+
klass = Class.new(WardenOmniAuth::Strategy)
|
37
|
+
klass.omni_name = name
|
38
|
+
Warden::Strategies.add(full_name, klass)
|
39
|
+
end
|
40
|
+
Warden::Strategies[full_name]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# The base omniauth warden strategy. This is inherited for each
|
45
|
+
# omniauth strategy
|
46
|
+
class Strategy < Warden::Strategies::Base
|
47
|
+
# make a specific callback for this strategy
|
48
|
+
def self.on_callback(&blk)
|
49
|
+
@on_callback = blk if blk
|
50
|
+
@on_callback || WardenOmniAuth.on_callback
|
51
|
+
end
|
52
|
+
|
53
|
+
# The name of the OmniAuth strategy to map to
|
54
|
+
def self.omni_name=(name)
|
55
|
+
@omni_name = name
|
56
|
+
end
|
57
|
+
|
58
|
+
# The name of the OmniAuth strategy to map to
|
59
|
+
def self.omni_name
|
60
|
+
@omni_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def authenticate!
|
64
|
+
session = env[SESSION_KEY]
|
65
|
+
session[SCOPE_KEY] = scope
|
66
|
+
|
67
|
+
# set the user if one exists
|
68
|
+
# otherwise, redirect for authentication
|
69
|
+
if user = (env['rack.auth'] || request['auth']) # TODO: Fix.. Completely insecure... do not use this will look in params for the auth. Apparently fixed in the new gem
|
70
|
+
|
71
|
+
success! self.class.on_callback[user]
|
72
|
+
else
|
73
|
+
path_prefix = OmniAuth::Configuration.instance.path_prefix
|
74
|
+
redirect! File.join(path_prefix, self.class.omni_name)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Pulled from extlib
|
80
|
+
# Convert to snake case.
|
81
|
+
#
|
82
|
+
# "FooBar".snake_case #=> "foo_bar"
|
83
|
+
# "HeadlineCNNNews".snake_case #=> "headline_cnn_news"
|
84
|
+
# "CNN".snake_case #=> "cnn"
|
85
|
+
#
|
86
|
+
# @return [String] Receiver converted to snake case.
|
87
|
+
#
|
88
|
+
# @api public
|
89
|
+
def self.snake_case(string)
|
90
|
+
return string.downcase if string.match(/\A[A-Z]+\z/)
|
91
|
+
string.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
92
|
+
gsub(/([a-z])([A-Z])/, '\1_\2').
|
93
|
+
downcase
|
94
|
+
end
|
95
|
+
|
96
|
+
def initialize(app)
|
97
|
+
# setup the warden strategies to wrap the omniauth ones
|
98
|
+
names = OmniAuth::Strategies.constants.map do |konstant|
|
99
|
+
name = WardenOmniAuth.snake_case(konstant.to_s)
|
100
|
+
end
|
101
|
+
WardenOmniAuth.setup_strategies(*names)
|
102
|
+
yield self if block_given?
|
103
|
+
@app = app
|
104
|
+
end
|
105
|
+
|
106
|
+
# redirect after a callback
|
107
|
+
def redirect_after_callback=(path)
|
108
|
+
@redirect_after_callback_path = path
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def redirect_after_callback_path
|
113
|
+
@redirect_after_callback_path ||= "/"
|
114
|
+
end
|
115
|
+
|
116
|
+
def call(env)
|
117
|
+
request = Rack::Request.new(env)
|
118
|
+
prefix = OmniAuth::Configuration.instance.path_prefix
|
119
|
+
if request.path =~ /^#{prefix}\/(.+?)\/callback$/i
|
120
|
+
strategy_name = $1
|
121
|
+
strategy = Warden::Strategies._strategies.keys.detect{|k| k.to_s == "omni_#{strategy_name}"}
|
122
|
+
|
123
|
+
if !strategy
|
124
|
+
Rack::Response.new("Unknown Handler", 401).finish
|
125
|
+
else
|
126
|
+
# Warden needs to use a hashie for looking up scope
|
127
|
+
# and strategy names
|
128
|
+
session = env[SESSION_KEY]
|
129
|
+
scope = session[SCOPE_KEY]
|
130
|
+
if scope.nil? || scope.to_s.length < 100 # have to protect against symbols :(. need a hashie
|
131
|
+
args = [strategy]
|
132
|
+
args << {:scope => scope.to_sym} if scope
|
133
|
+
response = Rack::Response.new
|
134
|
+
if env['warden'].authenticate? *args
|
135
|
+
response.redirect(redirect_after_callback_path)
|
136
|
+
response.finish
|
137
|
+
else
|
138
|
+
auth_path = request.path.gsub(/\/callback$/, "")
|
139
|
+
response.redirect(auth_path)
|
140
|
+
response.finish
|
141
|
+
end
|
142
|
+
else
|
143
|
+
Rack::Response.new("Bad Session", 400).finish
|
144
|
+
end
|
145
|
+
end
|
146
|
+
else
|
147
|
+
@app.call(env)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'nanotest'
|
2
|
+
require 'nanotest/contexts'
|
3
|
+
require 'rack'
|
4
|
+
require 'rack/test'
|
5
|
+
include Nanotest
|
6
|
+
include Nanotest::Contexts
|
7
|
+
|
8
|
+
require 'warden_omniauth'
|
9
|
+
|
10
|
+
Warden::Manager.serialize_into_session do |user|
|
11
|
+
user
|
12
|
+
end
|
13
|
+
|
14
|
+
Warden::Manager.serialize_from_session do |user|
|
15
|
+
user
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
module MyHelpers
|
20
|
+
def app
|
21
|
+
@app || create_app{|e| Rack::Response.new("OK").finish }
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_app(&blk)
|
25
|
+
failure = lambda{|e| Rack::Response.new("Can't login", 401).finish }
|
26
|
+
builder = Rack::Builder.new do
|
27
|
+
use Warden::Manager do |config|
|
28
|
+
config.failure_app = failure
|
29
|
+
config.default_strategies :omni_twitter
|
30
|
+
end
|
31
|
+
|
32
|
+
#use OmniAuth::Strategies::Twitter, key, sekrit
|
33
|
+
|
34
|
+
use WardenOmniAuth do |config|
|
35
|
+
$omni_auth = config
|
36
|
+
config.redirect_after_callback = "/redirect/path"
|
37
|
+
end
|
38
|
+
run blk
|
39
|
+
end.to_app
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
# WardenOmniauth
|
4
|
+
context do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
include MyHelpers
|
7
|
+
teardown { @_rack_mock_sessions = nil; @_rack_test_sessions = nil }
|
8
|
+
|
9
|
+
# shoudl setup all the omni auth strategies
|
10
|
+
test do
|
11
|
+
app
|
12
|
+
OmniAuth::Strategies.constants.each do |klass|
|
13
|
+
name = WardenOmniAuth.snake_case(klass.to_s)
|
14
|
+
assert { Warden::Strategies[:"omni_#{name}"] != nil }
|
15
|
+
assert { Warden::Strategies[:"omni_#{name}"].superclass == WardenOmniAuth::Strategy }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# test the middleware in a request
|
20
|
+
context do
|
21
|
+
setup do
|
22
|
+
@app = create_app do |e|
|
23
|
+
request = Rack::Request.new(e)
|
24
|
+
Rack::Response.new(request.path).finish
|
25
|
+
end
|
26
|
+
end
|
27
|
+
teardown { @_rack_mock_sessions = nil; @_rack_test_sessions = nil }
|
28
|
+
|
29
|
+
# test that any non /auth urls fall through to the app
|
30
|
+
test do
|
31
|
+
response = get "/foo", {}, {'rack.session' => {}}
|
32
|
+
assert { response.status == 200 }
|
33
|
+
assert { response.body.to_s == "/foo" }
|
34
|
+
end
|
35
|
+
|
36
|
+
# anything going to /auth/<strategy> should fall through to omniauth (the app)
|
37
|
+
test do
|
38
|
+
response = get "/auth/twitter", {}, {'rack.session' => {}}
|
39
|
+
assert { response.status == 200 }
|
40
|
+
assert { response.body.to_s == "/auth/twitter" }
|
41
|
+
end
|
42
|
+
|
43
|
+
# the callback url shoudl be intercepted and should raise if it's unknown
|
44
|
+
test do
|
45
|
+
assert { Warden::Strategies[:omni_does_not_exist].nil? }
|
46
|
+
response = get "/auth/does_not_exist/callback", {}, {'rack.session' => {}}
|
47
|
+
assert("status should be 401" ) { response.status == 401 }
|
48
|
+
assert("text should be Can't login" ) { response.body.to_s == "Can't login" }
|
49
|
+
end
|
50
|
+
|
51
|
+
# the callback url should be intercepted and should redirect back to the strategy if there is no user
|
52
|
+
# in rack['auth']
|
53
|
+
test do
|
54
|
+
response = get "/auth/twitter/callback", {}, { 'rack.auth' => nil, 'rack.session' => {}}
|
55
|
+
assert("status should be 302") { response.status == 302 }
|
56
|
+
assert("url should be /auth/twitter") { response.headers['Location'] == '/auth/twitter' }
|
57
|
+
end
|
58
|
+
|
59
|
+
# The session scope should not be too big
|
60
|
+
test do
|
61
|
+
session = {}
|
62
|
+
session[WardenOmniAuth::SCOPE_KEY] = "a" * 101
|
63
|
+
|
64
|
+
response = get "/auth/twitter/callback", {}, {'rack.session' => session }
|
65
|
+
assert("status should be 400" ) { response.status == 400 }
|
66
|
+
assert("body should be bad status" ) { response.body.to_s == "Bad Session" }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context do
|
71
|
+
teardown { @_rack_mock_sessions = nil; @_rack_test_sessions = nil }
|
72
|
+
setup do
|
73
|
+
$captures = []
|
74
|
+
@app = create_app do |e|
|
75
|
+
e['warden'].authenticate
|
76
|
+
$captures << e['warden'].user(:user)
|
77
|
+
Rack::Response.new("DONE").finish
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# The session scope should store the user
|
82
|
+
test do
|
83
|
+
|
84
|
+
session = {}
|
85
|
+
session[WardenOmniAuth::SCOPE_KEY] = "user"
|
86
|
+
expected_redirect = $omni_auth.redirect_after_callback_path
|
87
|
+
|
88
|
+
response = get("/auth/twitter/callback", {}, {'rack.session' => session, 'rack.auth' => {'user_info' => "fred"}})
|
89
|
+
|
90
|
+
assert("should be redirected") { response.status == 302 }
|
91
|
+
assert("should go to the redirect path"){ response.headers['Location'] == expected_redirect }
|
92
|
+
|
93
|
+
response = get(expected_redirect, {}, {'rack.session' => session })
|
94
|
+
assert("should have made it into the app") { $captures.size == 1 }
|
95
|
+
assert("should have captured the user"){ $captures.first[:user_info] == 'fred' }
|
96
|
+
end
|
97
|
+
|
98
|
+
# should give me different handlers for different callbacks
|
99
|
+
test do
|
100
|
+
begin
|
101
|
+
session = {}
|
102
|
+
session[WardenOmniAuth::SCOPE_KEY] = "user"
|
103
|
+
expected_redirect = $omni_auth.redirect_after_callback_path
|
104
|
+
|
105
|
+
Warden::Strategies[:omni_facebook].on_callback do |user|
|
106
|
+
{:facebook => "user"}
|
107
|
+
end
|
108
|
+
Warden::Strategies[:omni_twitter].on_callback do |user|
|
109
|
+
{:twitter => "user"}
|
110
|
+
end
|
111
|
+
|
112
|
+
response = get("/auth/facebook/callback", {}, {'rack.session' => session, 'rack.auth' => {'user_info' => "fred"}})
|
113
|
+
response = get expected_redirect, {}, {'rack.session' => session}
|
114
|
+
assert { $captures.size == 1 }
|
115
|
+
assert { $captures.first == {:facebook => "user"} }
|
116
|
+
$captures = []
|
117
|
+
|
118
|
+
session = {}
|
119
|
+
session[WardenOmniAuth::SCOPE_KEY] = "user"
|
120
|
+
response = get("/auth/twitter/callback", {}, {'rack.session' => session, 'rack.auth' => {'user_info' => 'fred'}})
|
121
|
+
response = get expected_redirect, {}, {'rack.session' => session}
|
122
|
+
assert { $captures.size == 1 }
|
123
|
+
assert { $captures.first == {:twitter => "user"} }
|
124
|
+
ensure
|
125
|
+
Warden::Strategies[:omni_facebook].on_callback &WardenOmniAuth::DEFAULT_CALLBACK
|
126
|
+
Warden::Strategies[:omni_twitter ].on_callback &WardenOmniAuth::DEFAULT_CALLBACK
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/warden_omniauth/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "warden_omniauth"
|
6
|
+
s.version = WardenOmniauth::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Daniel Neighman"]
|
9
|
+
s.email = ["has.sox@gmail.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/warden_omniauth"
|
11
|
+
s.summary = "A warden adapter for omniauth"
|
12
|
+
s.description = "A warden adapter for omniauth"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "warden_omniauth"
|
16
|
+
|
17
|
+
s.add_dependency "omniauth"
|
18
|
+
s.add_dependency "warden", ">=0.9"
|
19
|
+
|
20
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
24
|
+
s.require_path = 'lib'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: warden_omniauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Daniel Neighman
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-15 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: omniauth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: warden
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 25
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 9
|
47
|
+
version: "0.9"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: bundler
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: 1.0.0
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: A warden adapter for omniauth
|
67
|
+
email:
|
68
|
+
- has.sox@gmail.com
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
extra_rdoc_files: []
|
74
|
+
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- README.markdown
|
80
|
+
- Rakefile
|
81
|
+
- examples/twitter/config.ru
|
82
|
+
- lib/warden_omniauth.rb
|
83
|
+
- lib/warden_omniauth/version.rb
|
84
|
+
- test/test_helper.rb
|
85
|
+
- test/test_warden_omniauth.rb
|
86
|
+
- warden_omniauth.gemspec
|
87
|
+
has_rdoc: true
|
88
|
+
homepage: http://rubygems.org/gems/warden_omniauth
|
89
|
+
licenses: []
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
hash: 23
|
111
|
+
segments:
|
112
|
+
- 1
|
113
|
+
- 3
|
114
|
+
- 6
|
115
|
+
version: 1.3.6
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project: warden_omniauth
|
119
|
+
rubygems_version: 1.3.7
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: A warden adapter for omniauth
|
123
|
+
test_files: []
|
124
|
+
|