oa-core 0.2.0.beta3 → 0.2.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ module OmniAuth
10
10
  module Strategies
11
11
  autoload :Password, 'omniauth/strategies/password'
12
12
  end
13
-
13
+
14
14
  def self.strategies
15
15
  @@strategies ||= []
16
16
  end
@@ -1,9 +1,8 @@
1
1
  require 'omniauth/core'
2
2
 
3
3
  module OmniAuth
4
-
5
- module Strategy
6
-
4
+ class NoSessionError < StandardError; end
5
+ module Strategy
7
6
  def self.included(base)
8
7
  OmniAuth.strategies << base
9
8
  base.class_eval do
@@ -24,29 +23,40 @@ module OmniAuth
24
23
  end
25
24
 
26
25
  def call!(env)
26
+ raise OmniAuth::NoSessionError.new("You must provide a session to use OmniAuth.") unless env['rack.session']
27
+
27
28
  @env = env
28
29
  return mock_call!(env) if OmniAuth.config.test_mode
29
30
 
30
31
  if current_path == request_path && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
31
- status, headers, body = *call_app!
32
- @response = Rack::Response.new(body, status, headers)
33
- request_phase
32
+ if response = call_through_to_app
33
+ response
34
+ else
35
+ env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
36
+ request_phase
37
+ end
34
38
  elsif current_path == callback_path
39
+ env['omniauth.origin'] = session.delete('omniauth.origin')
40
+ env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
41
+
35
42
  callback_phase
36
43
  else
37
44
  if respond_to?(:other_phase)
38
45
  other_phase
39
46
  else
40
- call_app!
47
+ @app.call(env)
41
48
  end
42
49
  end
43
50
  end
44
51
 
45
52
  def mock_call!(env)
46
- if current_path == request_path
47
- status, headers, body = *call_app!
48
- @response = Rack::Response.new(body, status, headers)
49
- redirect callback_path
53
+ if current_path == request_path
54
+ if response = call_through_to_app
55
+ response
56
+ else
57
+ env['rack.session']['omniauth.origin'] = env['HTTP_REFERER']
58
+ redirect(callback_path)
59
+ end
50
60
  elsif current_path == callback_path
51
61
  @env['omniauth.auth'] = OmniAuth.mock_auth_for(name.to_sym)
52
62
  call_app!
@@ -61,7 +71,6 @@ module OmniAuth
61
71
 
62
72
  def callback_phase
63
73
  @env['omniauth.auth'] = auth_hash
64
-
65
74
  call_app!
66
75
  end
67
76
 
@@ -85,9 +94,15 @@ module OmniAuth
85
94
  request.query_string.empty? ? "" : "?#{request.query_string}"
86
95
  end
87
96
 
88
- def call_app!
89
- @env['omniauth.strategy'] = self
97
+ def call_through_to_app
98
+ status, headers, body = *call_app!
99
+ @response = Rack::Response.new(body, status, headers)
90
100
 
101
+ status == 404 ? nil : @response.finish
102
+ end
103
+
104
+ def call_app!
105
+ @env['omniauth.strategy'] = self
91
106
  @app.call(@env)
92
107
  end
93
108
 
@@ -26,7 +26,7 @@ module OmniAuth
26
26
  Rack::Builder.new {
27
27
  use OmniAuth::Test::PhonySession
28
28
  use *strat
29
- run lambda { |env| [200, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
29
+ run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
30
30
  }.to_app
31
31
  end
32
32
 
@@ -46,4 +46,4 @@ module OmniAuth
46
46
 
47
47
  end
48
48
 
49
- end
49
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oa-core
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.2.0.beta3
5
+ version: 0.2.0.beta4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-03 00:00:00 -06:00
13
+ date: 2011-02-11 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- hash: -4575558600340992300
126
+ hash: -3734078587052071503
127
127
  segments:
128
128
  - 0
129
129
  version: "0"