omniauth 1.0.0.pr2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of omniauth might be problematic. Click here for more details.

data/README.md CHANGED
@@ -18,7 +18,13 @@ one or more strategies. These strategies are generally released
18
18
  individually as RubyGems, and you can see a [community maintained list](https://github.com/intridea/omniauth/wiki/List-of-Strategies)
19
19
  on the wiki for this project.
20
20
 
21
- ## Adding OmniAuth to Your Application
21
+ One strategy, called `Developer`, is included with OmniAuth and provides
22
+ a completely unsecure, non-production-usable strategy that directly
23
+ prompts a user for authentication information and then passes it
24
+ straight through. You can use it as a placeholder when you start
25
+ development and easily swap in other strategies later.
26
+
27
+ ## Getting Started
22
28
 
23
29
  Each OmniAuth strategy is a Rack Middleware. That means that you can use
24
30
  it the same way that you use any other Rack middleware. For example, to
@@ -79,7 +85,7 @@ something like this:
79
85
 
80
86
  class SessionsController < ApplicationController
81
87
  def create
82
- @user = ̈User.find_or_create_from_auth_hash(auth_hash)
88
+ @user = User.find_or_create_from_auth_hash(auth_hash)
83
89
  self.current_user = @user
84
90
  redirect_to '/'
85
91
  end
data/lib/omniauth.rb CHANGED
@@ -2,7 +2,9 @@ require 'rack'
2
2
  require 'singleton'
3
3
 
4
4
  module OmniAuth
5
- module Strategies; end
5
+ module Strategies
6
+ autoload :Developer, 'omniauth/strategies/developer'
7
+ end
6
8
 
7
9
  autoload :Builder, 'omniauth/builder'
8
10
  autoload :Strategy, 'omniauth/strategy'
@@ -6,6 +6,8 @@ module OmniAuth
6
6
  # is able to provide into the InfoHash (stored as the `'info'`
7
7
  # key).
8
8
  class AuthHash < Hashie::Mash
9
+ def self.subkey_class; Hashie::Mash end
10
+
9
11
  # Tells you if this is considered to be a valid
10
12
  # OmniAuth AuthHash. The requirements for that
11
13
  # are that it has a provider name, a uid, and a
@@ -23,6 +25,8 @@ module OmniAuth
23
25
  end
24
26
 
25
27
  class InfoHash < Hashie::Mash
28
+ def self.subkey_class; Hashie::Mash end
29
+
26
30
  def name
27
31
  return self[:name] if self[:name]
28
32
  return "#{first_name} #{last_name}".strip if first_name? || last_name?
data/lib/omniauth/form.rb CHANGED
@@ -97,8 +97,8 @@ module OmniAuth
97
97
  header(options[:title],options[:header_info])
98
98
  end
99
99
 
100
- def self.build(title=nil,&block)
101
- form = OmniAuth::Form.new(:title => title)
100
+ def self.build(options = {},&block)
101
+ form = OmniAuth::Form.new(options)
102
102
  if block.arity > 0
103
103
  yield form
104
104
  else
@@ -0,0 +1,60 @@
1
+ require 'omniauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ # The Developer strategy is a very simple strategy that can be used as a
6
+ # placeholder in your application until a different authentication strategy
7
+ # is swapped in. It has zero security and should *never* be used in a
8
+ # production setting.
9
+ #
10
+ # ## Usage
11
+ #
12
+ # To use the Developer strategy, all you need to do is put it in like any
13
+ # other strategy:
14
+ #
15
+ # @example Basic Usage
16
+ #
17
+ # use OmniAuth::Builder do
18
+ # provider :developer
19
+ # end
20
+ #
21
+ # @example Custom Fields
22
+ #
23
+ # use OmniAuth::Builder do
24
+ # provider :developer,
25
+ # :fields => [:first_name, :last_name],
26
+ # :uid_field => :last_name
27
+ # end
28
+ #
29
+ # This will create a strategy that, when the user visits `/auth/developer`
30
+ # they will be presented a form that prompts for (by default) their name
31
+ # and email address. The auth hash will be populated with these fields and
32
+ # the `uid` will simply be set to the provided email.
33
+ class Developer
34
+ include OmniAuth::Strategy
35
+
36
+ option :fields, [:name, :email]
37
+ option :uid_field, :email
38
+
39
+ def request_phase
40
+ form = OmniAuth::Form.new(:title => "User Info", :url => callback_path)
41
+ options.fields.each do |field|
42
+ form.text_field field.to_s.capitalize.gsub("_", " "), field.to_s
43
+ end
44
+ form.button "Sign In"
45
+ form.to_response
46
+ end
47
+
48
+ uid do
49
+ request.params[options.uid_field.to_s]
50
+ end
51
+
52
+ info do
53
+ options.fields.inject({}) do |hash, field|
54
+ hash[field] = request.params[field.to_s]
55
+ hash
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module OmniAuth
2
- VERSION = "1.0.0.pr2"
2
+ VERSION = "1.0.0.rc1"
3
3
  end
data/omniauth.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.email = ['michael@intridea.com', 'sferik@gmail.com']
9
9
 
10
10
  gem.add_runtime_dependency 'rack'
11
- gem.add_runtime_dependency 'hashie'
11
+ gem.add_runtime_dependency 'hashie', '~> 1.2'
12
12
 
13
13
  gem.add_development_dependency 'maruku', '~> 0.6'
14
14
  gem.add_development_dependency 'simplecov', '~> 0.4'
@@ -91,6 +91,11 @@ describe OmniAuth::AuthHash do
91
91
  subject.info = {:first_name => 'Bob', :last_name => 'Examplar'}
92
92
  hash['info']['name'].should == 'Bob Examplar'
93
93
  end
94
+
95
+ it 'should not pollute the URL hash with "name" etc' do
96
+ subject.info = {'urls' => {'Homepage' => "http://homepage.com"}}
97
+ subject.to_hash['info']['urls'].should == {'Homepage' => "http://homepage.com"}
98
+ end
94
99
  end
95
100
 
96
101
  describe OmniAuth::AuthHash::InfoHash do
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Form do
4
+ describe '.build' do
5
+ it 'should yield the instance when called with a block and argument' do
6
+ OmniAuth::Form.build{|f| f.should be_kind_of(OmniAuth::Form)}
7
+ end
8
+
9
+ it 'should evaluate in the instance when called with a block and no argument' do
10
+ OmniAuth::Form.build{ self.class.should == OmniAuth::Form }
11
+ end
12
+ end
13
+
14
+ describe '#initialize' do
15
+ it 'the :url option should supply to the form that is built' do
16
+ OmniAuth::Form.new(:url => '/awesome').to_html.should be_include("action='/awesome'")
17
+ end
18
+
19
+ it 'the :title option should set an H1 tag' do
20
+ OmniAuth::Form.new(:title => 'Something Cool').to_html.should be_include('<h1>Something Cool</h1>')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Developer do
4
+ let(:app){ Rack::Builder.new do |b|
5
+ b.use Rack::Session::Cookie
6
+ b.use OmniAuth::Strategies::Developer
7
+ b.run lambda{|env| [200, {}, ['Not Found']]}
8
+ end.to_app }
9
+
10
+ context 'request phase' do
11
+ before(:each){ get '/auth/developer' }
12
+
13
+ it 'should display a form' do
14
+ last_response.status.should == 200
15
+ last_response.body.should be_include("<form")
16
+ end
17
+
18
+ it 'should have the callback as the action for the form' do
19
+ last_response.body.should be_include("action='/auth/developer/callback'")
20
+ end
21
+
22
+ it 'should have a text field for each of the fields' do
23
+ last_response.body.scan('<input').size.should == 2
24
+ end
25
+ end
26
+
27
+ context 'callback phase' do
28
+ let(:auth_hash){ last_request.env['omniauth.auth'] }
29
+
30
+ context 'with default options' do
31
+ before do
32
+ post '/auth/developer/callback', :name => 'Example User', :email => 'user@example.com'
33
+ end
34
+
35
+ it 'should set the name in the auth hash' do
36
+ auth_hash.info.name.should == 'Example User'
37
+ end
38
+
39
+ it 'should set the email in the auth hash' do
40
+ auth_hash.info.email.should == 'user@example.com'
41
+ end
42
+
43
+ it 'should set the uid to the email' do
44
+ auth_hash.uid.should == 'user@example.com'
45
+ end
46
+ end
47
+
48
+ context 'with custom options' do
49
+ let(:app){ Rack::Builder.new do |b|
50
+ b.use Rack::Session::Cookie
51
+ b.use OmniAuth::Strategies::Developer, :fields => [:first_name, :last_name], :uid_field => :last_name
52
+ b.run lambda{|env| [200, {}, ['Not Found']]}
53
+ end.to_app }
54
+
55
+ before do
56
+ @options = {:uid_field => :last_name, :fields => [:first_name, :last_name]}
57
+ post '/auth/developer/callback', :first_name => 'Example', :last_name => 'User'
58
+ end
59
+
60
+ it 'should set info fields properly' do
61
+ auth_hash.info.name.should == 'Example User'
62
+ end
63
+
64
+ it 'should set the uid properly' do
65
+ auth_hash.uid.should == 'User'
66
+ end
67
+ end
68
+ end
69
+ end
@@ -546,9 +546,17 @@ describe OmniAuth::Strategy do
546
546
  strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
547
547
  strategy.env['omniauth.origin'].should == 'http://example.com/origin'
548
548
  end
549
+
550
+ after do
551
+ OmniAuth.config.test_mode = false
552
+ end
549
553
  end
550
554
 
551
555
  context 'custom full_host' do
556
+ before do
557
+ OmniAuth.config.test_mode = true
558
+ end
559
+
552
560
  it 'should be the string when a string is there' do
553
561
  OmniAuth.config.full_host = 'my.host.com'
554
562
  strategy.full_host.should == 'my.host.com'
@@ -559,10 +567,18 @@ describe OmniAuth::Strategy do
559
567
  strategy.call(make_env('/auth/test', 'HOST' => 'my.host.net'))
560
568
  strategy.full_host.should == 'my.host.net'
561
569
  end
570
+
571
+ after do
572
+ OmniAuth.config.test_mode = false
573
+ end
562
574
  end
563
575
  end
564
576
 
565
577
  context 'setup phase' do
578
+ before do
579
+ OmniAuth.config.test_mode = true
580
+ end
581
+
566
582
  context 'when options[:setup] = true' do
567
583
  let(:strategy){ ExampleStrategy.new(app, :setup => true) }
568
584
  let(:app){lambda{|env| env['omniauth.strategy'].options[:awesome] = 'sauce' if env['PATH_INFO'] == '/auth/test/setup'; [404, {}, 'Awesome'] }}
@@ -597,5 +613,9 @@ describe OmniAuth::Strategy do
597
613
  strategy.options[:awesome].should == 'sauce'
598
614
  end
599
615
  end
616
+
617
+ after do
618
+ OmniAuth.config.test_mode = false
619
+ end
600
620
  end
601
621
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pr2
4
+ version: 1.0.0.rc1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-13 00:00:00.000000000Z
13
+ date: 2011-10-28 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
17
- requirement: &70329368740800 !ruby/object:Gem::Requirement
17
+ requirement: &70099446657480 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,21 +22,21 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70329368740800
25
+ version_requirements: *70099446657480
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: hashie
28
- requirement: &70329368740380 !ruby/object:Gem::Requirement
28
+ requirement: &70099446656940 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
- - - ! '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70329368740380
36
+ version_requirements: *70099446656940
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: maruku
39
- requirement: &70329368739880 !ruby/object:Gem::Requirement
39
+ requirement: &70099446656300 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0.6'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70329368739880
47
+ version_requirements: *70099446656300
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: simplecov
50
- requirement: &70329368739380 !ruby/object:Gem::Requirement
50
+ requirement: &70099446655720 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0.4'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70329368739380
58
+ version_requirements: *70099446655720
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rack-test
61
- requirement: &70329368738920 !ruby/object:Gem::Requirement
61
+ requirement: &70099446648340 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0.5'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70329368738920
69
+ version_requirements: *70099446648340
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rake
72
- requirement: &70329368738460 !ruby/object:Gem::Requirement
72
+ requirement: &70099446647380 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0.8'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70329368738460
80
+ version_requirements: *70099446647380
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rdiscount
83
- requirement: &70329368738000 !ruby/object:Gem::Requirement
83
+ requirement: &70099446646720 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '1.6'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70329368738000
91
+ version_requirements: *70099446646720
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rspec
94
- requirement: &70329368737540 !ruby/object:Gem::Requirement
94
+ requirement: &70099446645920 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ~>
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '2.5'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70329368737540
102
+ version_requirements: *70099446645920
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: yard
105
- requirement: &70329368737080 !ruby/object:Gem::Requirement
105
+ requirement: &70099446645460 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ~>
@@ -110,7 +110,7 @@ dependencies:
110
110
  version: '0.7'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70329368737080
113
+ version_requirements: *70099446645460
114
114
  description: A generalized Rack framework for multiple-provider authentication.
115
115
  email:
116
116
  - michael@intridea.com
@@ -133,6 +133,7 @@ files:
133
133
  - lib/omniauth/auth_hash.rb
134
134
  - lib/omniauth/builder.rb
135
135
  - lib/omniauth/form.rb
136
+ - lib/omniauth/strategies/developer.rb
136
137
  - lib/omniauth/strategy.rb
137
138
  - lib/omniauth/test.rb
138
139
  - lib/omniauth/test/phony_session.rb
@@ -142,6 +143,8 @@ files:
142
143
  - omniauth.gemspec
143
144
  - spec/omniauth/auth_hash_spec.rb
144
145
  - spec/omniauth/builder_spec.rb
146
+ - spec/omniauth/form_spec.rb
147
+ - spec/omniauth/strategies/developer_spec.rb
145
148
  - spec/omniauth/strategy_spec.rb
146
149
  - spec/omniauth_spec.rb
147
150
  - spec/spec_helper.rb
@@ -172,6 +175,8 @@ summary: A generalized Rack framework for multiple-provider authentication.
172
175
  test_files:
173
176
  - spec/omniauth/auth_hash_spec.rb
174
177
  - spec/omniauth/builder_spec.rb
178
+ - spec/omniauth/form_spec.rb
179
+ - spec/omniauth/strategies/developer_spec.rb
175
180
  - spec/omniauth/strategy_spec.rb
176
181
  - spec/omniauth_spec.rb
177
182
  - spec/spec_helper.rb