oa-core 0.2.0.beta4 → 0.2.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/oa-core.rb ADDED
@@ -0,0 +1 @@
1
+ require 'omniauth/core'
data/lib/omniauth/core.rb CHANGED
@@ -20,20 +20,20 @@ module OmniAuth
20
20
 
21
21
  @@defaults = {
22
22
  :path_prefix => '/auth',
23
- :on_failure => Proc.new do |env, message_key|
23
+ :on_failure => Proc.new do |env|
24
+ message_key = env['omniauth.error.type']
24
25
  new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
25
- [302, {'Location' => "#{new_path}", 'Content-Type'=> 'text/html'}, []]
26
+ [302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []]
26
27
  end,
27
28
  :form_css => Form::DEFAULT_CSS,
28
29
  :test_mode => false,
29
30
  :allowed_request_methods => [:get, :post],
30
31
  :mock_auth => {
31
32
  :default => {
33
+ 'provider' => 'default',
32
34
  'uid' => '1234',
33
35
  'user_info' => {
34
- 'name' => 'Bob Example',
35
- 'email' => 'bob@example.com',
36
- 'nickname' => 'bob'
36
+ 'name' => 'Bob Example'
37
37
  }
38
38
  }
39
39
  }
@@ -55,6 +55,23 @@ module OmniAuth
55
55
  end
56
56
  end
57
57
 
58
+ def add_mock(provider, mock={})
59
+ # Stringify keys recursively one level.
60
+ mock.stringify_keys!
61
+ mock.keys.each do|key|
62
+ if mock[key].is_a? Hash
63
+ mock[key].stringify_keys!
64
+ end
65
+ end
66
+
67
+ # Merge with the default mock and ensure provider is correct.
68
+ mock = self.mock_auth[:default].dup.merge(mock)
69
+ mock["provider"] = provider.to_s
70
+
71
+ # Add it to the mocks.
72
+ self.mock_auth[provider.to_sym] = mock
73
+ end
74
+
58
75
  attr_writer :on_failure
59
76
  attr_accessor :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host
60
77
  end
@@ -26,6 +26,9 @@ module OmniAuth
26
26
  raise OmniAuth::NoSessionError.new("You must provide a session to use OmniAuth.") unless env['rack.session']
27
27
 
28
28
  @env = env
29
+ @env['omniauth.strategy'] = self
30
+
31
+ setup_phase
29
32
  return mock_call!(env) if OmniAuth.config.test_mode
30
33
 
31
34
  if current_path == request_path && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
@@ -58,13 +61,27 @@ module OmniAuth
58
61
  redirect(callback_path)
59
62
  end
60
63
  elsif current_path == callback_path
61
- @env['omniauth.auth'] = OmniAuth.mock_auth_for(name.to_sym)
62
- call_app!
64
+ mocked_auth = OmniAuth.mock_auth_for(name.to_sym)
65
+ if mocked_auth.is_a?(Symbol)
66
+ fail!(mocked_auth)
67
+ else
68
+ @env['omniauth.auth'] = mocked_auth
69
+ call_app!
70
+ end
63
71
  else
64
72
  call_app!
65
73
  end
66
74
  end
67
75
 
76
+ def setup_phase
77
+ if options[:setup].respond_to?(:call)
78
+ options[:setup].call(env)
79
+ elsif options[:setup]
80
+ setup_env = env.merge('PATH_INFO' => setup_path, 'REQUEST_METHOD' => 'GET')
81
+ call_app!(setup_env)
82
+ end
83
+ end
84
+
68
85
  def request_phase
69
86
  raise NotImplementedError
70
87
  end
@@ -86,8 +103,12 @@ module OmniAuth
86
103
  options[:callback_path] || "#{path_prefix}/#{name}/callback"
87
104
  end
88
105
 
106
+ def setup_path
107
+ options[:setup_path] || "#{path_prefix}/#{name}/setup"
108
+ end
109
+
89
110
  def current_path
90
- request.path.sub(/\/$/,'')
111
+ request.path.downcase.sub(/\/$/,'')
91
112
  end
92
113
 
93
114
  def query_string
@@ -101,9 +122,8 @@ module OmniAuth
101
122
  status == 404 ? nil : @response.finish
102
123
  end
103
124
 
104
- def call_app!
105
- @env['omniauth.strategy'] = self
106
- @app.call(@env)
125
+ def call_app!(env = @env)
126
+ @app.call(env)
107
127
  end
108
128
 
109
129
  def auth_hash
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.beta4
5
+ version: 0.2.0.beta5
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-11 00:00:00 -06:00
13
+ date: 2011-03-01 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -99,6 +99,7 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
 
101
101
  files:
102
+ - lib/oa-core.rb
102
103
  - lib/omniauth/builder.rb
103
104
  - lib/omniauth/core.rb
104
105
  - lib/omniauth/form.rb
@@ -123,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
124
  requirements:
124
125
  - - ">="
125
126
  - !ruby/object:Gem::Version
126
- hash: -3734078587052071503
127
+ hash: -2207262758413508228
127
128
  segments:
128
129
  - 0
129
130
  version: "0"