warden_omniauth-jonrowe 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,20 +44,12 @@ class WardenOmniAuth
44
44
  # The base omniauth warden strategy. This is inherited for each
45
45
  # omniauth strategy
46
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
47
+ class << self
48
+ def on_callback(&blk)
49
+ @on_callback = blk if blk
50
+ @on_callback || WardenOmniAuth.on_callback
51
+ end
52
+ attr_accessor :omni_name
61
53
  end
62
54
 
63
55
  def authenticate!
@@ -104,12 +96,14 @@ class WardenOmniAuth
104
96
 
105
97
  # redirect after a callback
106
98
  def redirect_after_callback=(path)
107
- @redirect_after_callback_path = path
99
+ @generate_path_to_redirect_after_callback = proc { path }
100
+ end
101
+ def redirect_after_callback(&block)
102
+ @generate_path_to_redirect_after_callback = block
108
103
  end
109
104
 
110
-
111
- def redirect_after_callback_path
112
- @redirect_after_callback_path ||= "/"
105
+ def redirect_after_callback_path(env={})
106
+ (@generate_path_to_redirect_after_callback || proc { "/" } ).call(env)
113
107
  end
114
108
 
115
109
  def call(env)
@@ -131,7 +125,7 @@ class WardenOmniAuth
131
125
  args << {:scope => scope.to_sym} if scope
132
126
  response = Rack::Response.new
133
127
  if env['warden'].authenticate? *args
134
- response.redirect(redirect_after_callback_path)
128
+ response.redirect(redirect_after_callback_path(env))
135
129
  response.finish
136
130
  else
137
131
  auth_path = request.path.gsub(/\/callback$/, "")
@@ -1,3 +1,3 @@
1
1
  module WardenOmniauth
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -96,6 +96,18 @@ context do
96
96
  assert("should have made it into the app") { $captures.size == 1 }
97
97
  assert("should have captured the user"){ $captures.first[:info] == 'fred' }
98
98
  end
99
+ test do
100
+ session = { WardenOmniAuth::SCOPE_KEY => "user" }
101
+ $omni_auth.redirect_after_callback do |env|
102
+ assert('enviromnent passed to block') { env.fetch('omniauth.auth',{})['info'] == 'fred' }
103
+ '/my/dynamic/path'
104
+ end
105
+
106
+ response = get("/auth/twitter/callback", {}, {'rack.session' => session, 'omniauth.auth' => {'info' => "fred"}})
107
+
108
+ assert("should be redirected") { response.status == 302 }
109
+ assert("should go to the dynamic redirect path") { response.headers['Location'] == '/my/dynamic/path' }
110
+ end
99
111
 
100
112
  # should give me different handlers for different callbacks
101
113
  test do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden_omniauth-jonrowe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-17 00:00:00.000000000 Z
13
+ date: 2012-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: omniauth
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: -999869407491389986
95
+ hash: -1914201548067094911
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements: