omniauth-identity 1.0.0.rc1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +27 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.markdown +149 -35
- data/lib/omniauth-identity/version.rb +1 -1
- data/lib/omniauth/identity.rb +6 -5
- data/lib/omniauth/identity/model.rb +9 -8
- data/lib/omniauth/identity/models/active_record.rb +3 -3
- data/lib/omniauth/identity/models/couch_potato.rb +31 -0
- data/lib/omniauth/identity/models/data_mapper.rb +32 -0
- data/lib/omniauth/identity/models/mongoid.rb +2 -2
- data/lib/omniauth/identity/secure_password.rb +1 -1
- data/lib/omniauth/strategies/identity.rb +34 -17
- data/omniauth-identity.gemspec +16 -13
- data/spec/omniauth/identity/model_spec.rb +39 -35
- data/spec/omniauth/identity/models/active_record_spec.rb +12 -12
- data/spec/omniauth/identity/models/couch_potato_spec.rb +16 -0
- data/spec/omniauth/identity/models/data_mapper_spec.rb +24 -0
- data/spec/omniauth/identity/models/mongoid_spec.rb +14 -9
- data/spec/omniauth/identity/secure_password_spec.rb +3 -5
- data/spec/omniauth/strategies/identity_spec.rb +30 -19
- data/spec/spec_helper.rb +6 -0
- metadata +147 -69
- data/Gemfile.lock +0 -88
@@ -68,7 +68,7 @@ module OmniAuth
|
|
68
68
|
# Encrypts the password into the password_digest attribute.
|
69
69
|
def password=(unencrypted_password)
|
70
70
|
@password = unencrypted_password
|
71
|
-
|
71
|
+
if unencrypted_password && !unencrypted_password.empty?
|
72
72
|
self.password_digest = BCrypt::Password.create(unencrypted_password)
|
73
73
|
end
|
74
74
|
end
|
@@ -1,23 +1,30 @@
|
|
1
1
|
module OmniAuth
|
2
2
|
module Strategies
|
3
|
-
# The identity strategy allows you to provide simple internal
|
3
|
+
# The identity strategy allows you to provide simple internal
|
4
4
|
# user authentication using the same process flow that you
|
5
5
|
# use for external OmniAuth providers.
|
6
6
|
class Identity
|
7
7
|
include OmniAuth::Strategy
|
8
8
|
|
9
9
|
option :fields, [:name, :email]
|
10
|
+
option :on_login, nil
|
11
|
+
option :on_registration, nil
|
10
12
|
option :on_failed_registration, nil
|
13
|
+
option :locate_conditions, lambda{|req| {model.auth_key => req['auth_key']} }
|
11
14
|
|
12
15
|
def request_phase
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
if options[:on_login]
|
17
|
+
options[:on_login].call(self.env)
|
18
|
+
else
|
19
|
+
OmniAuth::Form.build(
|
20
|
+
:title => (options[:title] || "Identity Verification"),
|
21
|
+
:url => callback_path
|
22
|
+
) do |f|
|
23
|
+
f.text_field 'Login', 'auth_key'
|
24
|
+
f.password_field 'Password', 'password'
|
25
|
+
f.html "<p align='center'><a href='#{registration_path}'>Create an Identity</a></p>"
|
26
|
+
end.to_response
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
def callback_phase
|
@@ -38,13 +45,17 @@ module OmniAuth
|
|
38
45
|
end
|
39
46
|
|
40
47
|
def registration_form
|
41
|
-
|
42
|
-
options[:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
if options[:on_registration]
|
49
|
+
options[:on_registration].call(self.env)
|
50
|
+
else
|
51
|
+
OmniAuth::Form.build(:title => 'Register Identity') do |f|
|
52
|
+
options[:fields].each do |field|
|
53
|
+
f.text_field field.to_s.capitalize, field.to_s
|
54
|
+
end
|
55
|
+
f.password_field 'Password', 'password'
|
56
|
+
f.password_field 'Confirm Password', 'password_confirmation'
|
57
|
+
end.to_response
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
61
|
def registration_phase
|
@@ -75,7 +86,13 @@ module OmniAuth
|
|
75
86
|
end
|
76
87
|
|
77
88
|
def identity
|
78
|
-
|
89
|
+
if options.locate_conditions.is_a? Proc
|
90
|
+
conditions = instance_exec(request, &options.locate_conditions)
|
91
|
+
conditions.to_hash
|
92
|
+
else
|
93
|
+
conditions = options.locate_conditions.to_hash
|
94
|
+
end
|
95
|
+
@identity ||= model.authenticate(conditions, request['password'] )
|
79
96
|
end
|
80
97
|
|
81
98
|
def model
|
data/omniauth-identity.gemspec
CHANGED
@@ -2,25 +2,28 @@
|
|
2
2
|
require File.dirname(__FILE__) + '/lib/omniauth-identity/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.add_runtime_dependency 'omniauth'
|
5
|
+
gem.add_runtime_dependency 'omniauth'
|
6
|
+
gem.add_runtime_dependency 'bcrypt'
|
6
7
|
|
7
|
-
gem.add_development_dependency 'maruku'
|
8
|
-
gem.add_development_dependency 'simplecov'
|
9
|
-
gem.add_development_dependency 'rack-test'
|
10
|
-
gem.add_development_dependency 'rake'
|
11
|
-
gem.add_development_dependency 'rspec', '~>
|
12
|
-
gem.add_development_dependency '
|
13
|
-
gem.add_development_dependency '
|
14
|
-
gem.add_development_dependency '
|
15
|
-
gem.add_development_dependency 'bson_ext'
|
8
|
+
gem.add_development_dependency 'maruku'
|
9
|
+
gem.add_development_dependency 'simplecov'
|
10
|
+
gem.add_development_dependency 'rack-test'
|
11
|
+
gem.add_development_dependency 'rake'
|
12
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
13
|
+
gem.add_development_dependency 'activerecord'
|
14
|
+
gem.add_development_dependency 'mongoid'
|
15
|
+
gem.add_development_dependency 'datamapper'
|
16
|
+
gem.add_development_dependency 'bson_ext'
|
17
|
+
gem.add_development_dependency 'byebug'
|
18
|
+
gem.add_development_dependency 'couch_potato'
|
16
19
|
|
17
20
|
gem.name = 'omniauth-identity'
|
18
21
|
gem.version = OmniAuth::Identity::VERSION
|
19
22
|
gem.description = %q{Internal authentication handlers for OmniAuth.}
|
20
23
|
gem.summary = gem.description
|
21
|
-
gem.
|
22
|
-
gem.
|
23
|
-
gem.
|
24
|
+
gem.homepage = 'http://github.com/omniauth/omniauth-identity'
|
25
|
+
gem.authors = ['Andrew Roberts', 'Michael Bleigh']
|
26
|
+
gem.license = 'MIT'
|
24
27
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
25
28
|
gem.files = `git ls-files`.split("\n")
|
26
29
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
class ExampleModel
|
4
2
|
include OmniAuth::Identity::Model
|
5
3
|
end
|
@@ -9,19 +7,25 @@ describe OmniAuth::Identity::Model do
|
|
9
7
|
subject{ ExampleModel }
|
10
8
|
|
11
9
|
describe '.locate' do
|
12
|
-
it('should be abstract'){
|
10
|
+
it('should be abstract'){ expect{ subject.locate('abc') }.to raise_error(NotImplementedError) }
|
13
11
|
end
|
14
12
|
|
15
13
|
describe '.authenticate' do
|
16
14
|
it 'should call locate and then authenticate' do
|
17
|
-
mocked_instance =
|
18
|
-
subject.
|
19
|
-
subject.authenticate('example','pass').
|
15
|
+
mocked_instance = double('ExampleModel', :authenticate => 'abbadoo')
|
16
|
+
allow(subject).to receive(:locate).with('email' => 'example').and_return(mocked_instance)
|
17
|
+
expect(subject.authenticate({'email' => 'example'},'pass')).to eq('abbadoo')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should call locate with additional scopes when provided' do
|
21
|
+
mocked_instance = double('ExampleModel', :authenticate => 'abbadoo')
|
22
|
+
allow(subject).to receive(:locate).with('email' => 'example', 'user_type' => 'admin').and_return(mocked_instance)
|
23
|
+
expect(subject.authenticate({'email' => 'example', 'user_type' => 'admin'}, 'pass')).to eq('abbadoo')
|
20
24
|
end
|
21
25
|
|
22
26
|
it 'should recover gracefully if locate is nil' do
|
23
|
-
subject.
|
24
|
-
subject.authenticate('blah','foo').
|
27
|
+
allow(subject).to receive(:locate).and_return(nil)
|
28
|
+
expect(subject.authenticate('blah','foo')).to be false
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -30,87 +34,87 @@ describe OmniAuth::Identity::Model do
|
|
30
34
|
subject{ ExampleModel.new }
|
31
35
|
|
32
36
|
describe '#authenticate' do
|
33
|
-
it('should be abstract'){
|
37
|
+
it('should be abstract'){ expect{ subject.authenticate('abc') }.to raise_error(NotImplementedError) }
|
34
38
|
end
|
35
39
|
|
36
40
|
describe '#uid' do
|
37
41
|
it 'should default to #id' do
|
38
|
-
subject.
|
39
|
-
subject.
|
40
|
-
subject.uid.
|
42
|
+
allow(subject).to receive(:respond_to?).with(:id).and_return(true)
|
43
|
+
allow(subject).to receive(:id).and_return 'wakka-do'
|
44
|
+
expect(subject.uid).to eq('wakka-do')
|
41
45
|
end
|
42
46
|
|
43
47
|
it 'should stringify it' do
|
44
|
-
subject.
|
45
|
-
subject.uid.
|
48
|
+
allow(subject).to receive(:id).and_return 123
|
49
|
+
expect(subject.uid).to eq('123')
|
46
50
|
end
|
47
51
|
|
48
52
|
it 'should raise NotImplementedError if #id is not defined' do
|
49
|
-
subject.
|
50
|
-
|
53
|
+
allow(subject).to receive(:respond_to?).with(:id).and_return(false)
|
54
|
+
expect{ subject.uid }.to raise_error(NotImplementedError)
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
58
|
describe '#auth_key' do
|
55
59
|
it 'should default to #email' do
|
56
|
-
subject.
|
57
|
-
subject.
|
58
|
-
subject.auth_key.
|
60
|
+
allow(subject).to receive(:respond_to?).with(:email).and_return(true)
|
61
|
+
allow(subject).to receive(:email).and_return('bob@bob.com')
|
62
|
+
expect(subject.auth_key).to eq('bob@bob.com')
|
59
63
|
end
|
60
64
|
|
61
65
|
it 'should use the class .auth_key' do
|
62
66
|
subject.class.auth_key 'login'
|
63
|
-
subject.
|
64
|
-
subject.auth_key.
|
67
|
+
allow(subject).to receive(:login).and_return 'bob'
|
68
|
+
expect(subject.auth_key).to eq('bob')
|
65
69
|
subject.class.auth_key nil
|
66
70
|
end
|
67
71
|
|
68
72
|
it 'should raise a NotImplementedError if the auth_key method is not defined' do
|
69
|
-
|
73
|
+
expect{ subject.auth_key }.to raise_error(NotImplementedError)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
73
77
|
describe '#auth_key=' do
|
74
78
|
it 'should default to setting email' do
|
75
|
-
subject.
|
76
|
-
subject.
|
79
|
+
allow(subject).to receive(:respond_to?).with(:email=).and_return(true)
|
80
|
+
expect(subject).to receive(:email=).with 'abc'
|
77
81
|
|
78
82
|
subject.auth_key = 'abc'
|
79
83
|
end
|
80
84
|
|
81
85
|
it 'should use a custom .auth_key if one is provided' do
|
82
86
|
subject.class.auth_key 'login'
|
83
|
-
subject.
|
84
|
-
subject.
|
87
|
+
allow(subject).to receive(:respond_to?).with(:login=).and_return(true)
|
88
|
+
expect(subject).to receive(:login=).with('abc')
|
85
89
|
|
86
90
|
subject.auth_key = 'abc'
|
87
91
|
end
|
88
92
|
|
89
93
|
it 'should raise a NotImplementedError if the autH_key method is not defined' do
|
90
|
-
|
94
|
+
expect{ subject.auth_key = 'broken' }.to raise_error(NotImplementedError)
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
94
98
|
describe '#info' do
|
95
99
|
it 'should include attributes that are set' do
|
96
|
-
subject.
|
97
|
-
subject.
|
100
|
+
allow(subject).to receive(:name).and_return('Bob Bobson')
|
101
|
+
allow(subject).to receive(:nickname).and_return('bob')
|
98
102
|
|
99
|
-
subject.info.
|
103
|
+
expect(subject.info).to eq({
|
100
104
|
'name' => 'Bob Bobson',
|
101
105
|
'nickname' => 'bob'
|
102
|
-
}
|
106
|
+
})
|
103
107
|
end
|
104
108
|
|
105
109
|
it 'should automatically set name off of nickname' do
|
106
|
-
subject.
|
110
|
+
allow(subject).to receive(:nickname).and_return('bob')
|
107
111
|
subject.info['name'] == 'bob'
|
108
112
|
end
|
109
113
|
|
110
114
|
it 'should not overwrite a provided name' do
|
111
|
-
subject.
|
112
|
-
subject.
|
113
|
-
subject.info['name'].
|
115
|
+
allow(subject).to receive(:name).and_return('Awesome Dude')
|
116
|
+
allow(subject).to receive(:first_name).and_return('Frank')
|
117
|
+
expect(subject.info['name']).to eq('Awesome Dude')
|
114
118
|
end
|
115
119
|
end
|
116
120
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe(OmniAuth::Identity::Models::ActiveRecord, :db => true) do
|
4
|
-
class TestIdentity < OmniAuth::Identity::Models::ActiveRecord
|
5
|
-
auth_key :ham_sandwich
|
6
|
-
end
|
2
|
+
class TestIdentity < OmniAuth::Identity::Models::ActiveRecord; end
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
describe "model", type: :model do
|
5
|
+
subject { TestIdentity }
|
6
|
+
|
7
|
+
it 'should delegate locate to the where query method' do
|
8
|
+
allow(subject).to receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
|
9
|
+
expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should not use STI rules for its table name' do
|
13
|
+
expect(subject.table_name).to eq('test_identities')
|
14
|
+
end
|
15
15
|
end
|
16
16
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
describe(OmniAuth::Identity::Models::CouchPotatoModule, :db => true) do
|
2
|
+
class CouchPotatoTestIdentity
|
3
|
+
include CouchPotato::Persistence
|
4
|
+
include OmniAuth::Identity::Models::CouchPotatoModule
|
5
|
+
auth_key :ham_sandwich
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'model', type: :model do
|
9
|
+
subject { CouchPotatoTestIdentity }
|
10
|
+
|
11
|
+
it 'should delegate locate to the where query method' do
|
12
|
+
allow(subject).to receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
|
13
|
+
expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe(OmniAuth::Identity::Models::DataMapper, :db => true) do
|
2
|
+
class DataMapperTestIdentity
|
3
|
+
include DataMapper::Resource
|
4
|
+
include OmniAuth::Identity::Models::DataMapper
|
5
|
+
|
6
|
+
property :id, Serial
|
7
|
+
auth_key :ham_sandwich
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
DataMapper.finalize
|
13
|
+
@resource = DataMapperTestIdentity.new
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'model', type: :model do
|
17
|
+
subject { DataMapperTestIdentity }
|
18
|
+
|
19
|
+
it 'should delegate locate to the all query method' do
|
20
|
+
allow(subject).to receive(:all).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
|
21
|
+
expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,18 +1,23 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe(OmniAuth::Identity::Models::Mongoid, :db => true) do
|
4
2
|
class MongoidTestIdentity
|
5
3
|
include Mongoid::Document
|
6
4
|
include OmniAuth::Identity::Models::Mongoid
|
7
5
|
auth_key :ham_sandwich
|
6
|
+
store_in database: 'db1', collection: 'mongoid_test_identities', client: 'secondary'
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
describe "model", type: :model do
|
10
|
+
subject { MongoidTestIdentity }
|
11
|
+
|
12
|
+
it { is_expected.to be_mongoid_document }
|
13
|
+
|
14
|
+
it 'does not munge collection name' do
|
15
|
+
is_expected.to be_stored_in(database: 'db1', collection: 'mongoid_test_identities', client: 'secondary')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should delegate locate to the where query method' do
|
19
|
+
allow(subject).to receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
|
20
|
+
expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
class HasTheMethod
|
4
2
|
def self.has_secure_password; end
|
5
3
|
end
|
@@ -9,19 +7,19 @@ end
|
|
9
7
|
|
10
8
|
describe OmniAuth::Identity::SecurePassword do
|
11
9
|
it 'should extend with the class methods if it does not have the method' do
|
12
|
-
DoesNotHaveTheMethod.
|
10
|
+
expect(DoesNotHaveTheMethod).to receive(:extend).with(OmniAuth::Identity::SecurePassword::ClassMethods)
|
13
11
|
DoesNotHaveTheMethod.send(:include, OmniAuth::Identity::SecurePassword)
|
14
12
|
end
|
15
13
|
|
16
14
|
it 'should not extend if the method is already defined' do
|
17
|
-
HasTheMethod.
|
15
|
+
expect(HasTheMethod).not_to receive(:extend)
|
18
16
|
HasTheMethod.send(:include, OmniAuth::Identity::SecurePassword)
|
19
17
|
end
|
20
18
|
|
21
19
|
it 'should respond to has_secure_password afterwards' do
|
22
20
|
[HasTheMethod,DoesNotHaveTheMethod].each do |klass|
|
23
21
|
klass.send(:include, OmniAuth::Identity::SecurePassword)
|
24
|
-
klass.
|
22
|
+
expect(klass).to be_respond_to(:has_secure_password)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
class MockIdentity; end
|
4
2
|
|
5
3
|
describe OmniAuth::Strategies::Identity do
|
@@ -14,7 +12,7 @@ describe OmniAuth::Strategies::Identity do
|
|
14
12
|
identity_options = {:model => MockIdentity}.merge(identity_options)
|
15
13
|
old_app = self.app
|
16
14
|
self.app = Rack::Builder.app do
|
17
|
-
use Rack::Session::Cookie
|
15
|
+
use Rack::Session::Cookie, secret: '1234567890qwertyuiop'
|
18
16
|
use OmniAuth::Strategies::Identity, identity_options
|
19
17
|
run lambda{|env| [404, {'env' => env}, ["HELLO!"]]}
|
20
18
|
end
|
@@ -32,41 +30,53 @@ describe OmniAuth::Strategies::Identity do
|
|
32
30
|
describe '#request_phase' do
|
33
31
|
it 'should display a form' do
|
34
32
|
get '/auth/identity'
|
35
|
-
last_response.body.
|
33
|
+
expect(last_response.body).to be_include("<form")
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
describe '#callback_phase' do
|
40
|
-
let(:user){
|
38
|
+
let(:user){ double(:uid => 'user1', :info => {'name' => 'Rockefeller'})}
|
41
39
|
|
42
40
|
context 'with valid credentials' do
|
43
41
|
before do
|
44
|
-
MockIdentity.
|
42
|
+
allow(MockIdentity).to receive('auth_key').and_return('email')
|
43
|
+
expect(MockIdentity).to receive('authenticate').with({'email' => 'john'},'awesome').and_return(user)
|
45
44
|
post '/auth/identity/callback', :auth_key => 'john', :password => 'awesome'
|
46
45
|
end
|
47
46
|
|
48
47
|
it 'should populate the auth hash' do
|
49
|
-
auth_hash.
|
48
|
+
expect(auth_hash).to be_kind_of(Hash)
|
50
49
|
end
|
51
50
|
|
52
51
|
it 'should populate the uid' do
|
53
|
-
auth_hash['uid'].
|
52
|
+
expect(auth_hash['uid']).to eq('user1')
|
54
53
|
end
|
55
54
|
|
56
55
|
it 'should populate the info hash' do
|
57
|
-
auth_hash['info'].
|
56
|
+
expect(auth_hash['info']).to eq({'name' => 'Rockefeller'})
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
60
|
context 'with invalid credentials' do
|
62
61
|
before do
|
62
|
+
allow(MockIdentity).to receive('auth_key').and_return('email')
|
63
63
|
OmniAuth.config.on_failure = lambda{|env| [401, {}, [env['omniauth.error.type'].inspect]]}
|
64
|
-
MockIdentity.
|
64
|
+
expect(MockIdentity).to receive(:authenticate).with({'email' => 'wrong'},'login').and_return(false)
|
65
65
|
post '/auth/identity/callback', :auth_key => 'wrong', :password => 'login'
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'should fail with :invalid_credentials' do
|
69
|
-
last_response.body.
|
69
|
+
expect(last_response.body).to eq(':invalid_credentials')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'with auth scopes' do
|
74
|
+
|
75
|
+
it 'should evaluate and pass through conditions proc' do
|
76
|
+
allow(MockIdentity).to receive('auth_key').and_return('email')
|
77
|
+
set_app!( :locate_conditions => lambda{|req| {model.auth_key => req['auth_key'], 'user_type' => 'admin'} } )
|
78
|
+
expect(MockIdentity).to receive('authenticate').with( {'email' => 'john', 'user_type' => 'admin'}, 'awesome' ).and_return(user)
|
79
|
+
post '/auth/identity/callback', :auth_key => 'john', :password => 'awesome'
|
70
80
|
end
|
71
81
|
end
|
72
82
|
end
|
@@ -74,27 +84,28 @@ describe OmniAuth::Strategies::Identity do
|
|
74
84
|
describe '#registration_form' do
|
75
85
|
it 'should trigger from /auth/identity/register by default' do
|
76
86
|
get '/auth/identity/register'
|
77
|
-
last_response.body.
|
87
|
+
expect(last_response.body).to be_include("Register Identity")
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
81
91
|
describe '#registration_phase' do
|
82
92
|
context 'with successful creation' do
|
83
93
|
let(:properties){ {
|
84
|
-
:name => 'Awesome Dude',
|
94
|
+
:name => 'Awesome Dude',
|
85
95
|
:email => 'awesome@example.com',
|
86
96
|
:password => 'face',
|
87
97
|
:password_confirmation => 'face'
|
88
98
|
} }
|
89
99
|
|
90
100
|
before do
|
91
|
-
|
92
|
-
|
101
|
+
allow(MockIdentity).to receive('auth_key').and_return('email')
|
102
|
+
m = double(:uid => 'abc', :name => 'Awesome Dude', :email => 'awesome@example.com', :info => {:name => 'DUUUUDE!'}, :persisted? => true)
|
103
|
+
expect(MockIdentity).to receive(:create).with(properties).and_return(m)
|
93
104
|
end
|
94
105
|
|
95
106
|
it 'should set the auth hash' do
|
96
107
|
post '/auth/identity/register', properties
|
97
|
-
auth_hash['uid'].
|
108
|
+
expect(auth_hash['uid']).to eq('abc')
|
98
109
|
end
|
99
110
|
end
|
100
111
|
|
@@ -107,13 +118,13 @@ describe OmniAuth::Strategies::Identity do
|
|
107
118
|
} }
|
108
119
|
|
109
120
|
before do
|
110
|
-
MockIdentity.
|
121
|
+
expect(MockIdentity).to receive(:create).with(properties).and_return(double(:persisted? => false))
|
111
122
|
end
|
112
123
|
|
113
124
|
context 'default' do
|
114
125
|
it 'should show registration form' do
|
115
126
|
post '/auth/identity/register', properties
|
116
|
-
last_response.body.
|
127
|
+
expect(last_response.body).to be_include("Register Identity")
|
117
128
|
end
|
118
129
|
end
|
119
130
|
|
@@ -121,7 +132,7 @@ describe OmniAuth::Strategies::Identity do
|
|
121
132
|
it 'should set the identity hash' do
|
122
133
|
set_app!(:on_failed_registration => lambda{|env| [404, {'env' => env}, ["HELLO!"]]}) do
|
123
134
|
post '/auth/identity/register', properties
|
124
|
-
identity_hash.
|
135
|
+
expect(identity_hash).not_to be_nil
|
125
136
|
end
|
126
137
|
end
|
127
138
|
end
|