devise-stormpath 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Guardfile +24 -0
- data/Rakefile +5 -0
- data/devise-stormpath.gemspec +5 -2
- data/lib/devise/stormpath/model.rb +3 -4
- data/lib/devise/stormpath/strategy.rb +0 -2
- data/lib/devise/stormpath/version.rb +1 -1
- data/lib/devise-stormpath.rb +6 -1
- data/spec/devise/stormpath/model_spec.rb +33 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/client.rb +6 -0
- metadata +74 -11
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara features specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/Rakefile
CHANGED
data/devise-stormpath.gemspec
CHANGED
@@ -7,7 +7,6 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.summary = 'Devise extension to allow authentication via Stormpath'
|
9
9
|
s.email = 'liquidautumn@gmail.com'
|
10
|
-
s.homepage = 'https://github.com/liquidautumn/devise-stormpath'
|
11
10
|
s.description = s.summary
|
12
11
|
s.author = 'Denis Grankin'
|
13
12
|
|
@@ -18,6 +17,10 @@ Gem::Specification.new do |s|
|
|
18
17
|
|
19
18
|
s.add_dependency('devise')
|
20
19
|
s.add_dependency('stormpath-rails')
|
20
|
+
s.add_dependency('activesupport')
|
21
21
|
|
22
|
-
s.add_development_dependency('rake')
|
22
|
+
s.add_development_dependency('rake', '~> 10.0.2')
|
23
|
+
s.add_development_dependency('rspec', '~> 2.12.0')
|
24
|
+
s.add_development_dependency('guard-rspec', '~> 2.2.1')
|
25
|
+
s.add_development_dependency('rb-inotify', '~> 0.8.8')
|
23
26
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'stormpath-rails'
|
1
|
+
require "active_support/concern"
|
3
2
|
|
4
3
|
module Devise
|
5
4
|
module Models
|
@@ -12,10 +11,10 @@ module Devise
|
|
12
11
|
end
|
13
12
|
|
14
13
|
module ClassMethods
|
14
|
+
#TODO support login with email
|
15
15
|
def authenticate_with_stormpath(attributes={})
|
16
|
-
login = (self.case_insensitive_keys || []).include?(:username) ? attributes[:username].downcase : attributes[:username]
|
17
16
|
begin
|
18
|
-
account = ::Stormpath::Rails::Client.authenticate_account(
|
17
|
+
account = ::Stormpath::Rails::Client.authenticate_account(attributes[:username], attributes[:password])
|
19
18
|
return self.where(stormpath_url: account.get_href).first
|
20
19
|
rescue ResourceError => error
|
21
20
|
return nil
|
data/lib/devise-stormpath.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
require 'devise'
|
2
|
+
require 'stormpath-rails'
|
3
|
+
|
4
|
+
require 'devise/stormpath/strategy'
|
5
|
+
|
6
|
+
Warden::Strategies.add(:stormpath_authenticatable, Devise::Strategies::StormpathAuthenticatable)
|
2
7
|
|
3
8
|
Devise.add_module(:stormpath_authenticatable,
|
4
|
-
:route => :session, :strategy
|
9
|
+
:route => :session, :strategy => true, :controller => :sessions, :model => 'devise/stormpath/model')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "devise/stormpath/model"
|
3
|
+
|
4
|
+
class User
|
5
|
+
include Devise::Models::StormpathAuthenticatable
|
6
|
+
end
|
7
|
+
|
8
|
+
class ResourceError < Exception
|
9
|
+
end
|
10
|
+
|
11
|
+
describe Devise::Models::StormpathAuthenticatable do
|
12
|
+
|
13
|
+
let(:user) { mock("user") }
|
14
|
+
|
15
|
+
describe "#authenticate_with_stormpath" do
|
16
|
+
it "should return user if authenticated on stormpath and local user exists with returned href" do
|
17
|
+
Stormpath::Rails::Client.should_receive(:authenticate_account).with("username", "password").and_return(mock("account", get_href: "user href"))
|
18
|
+
User.should_receive(:where).with(stormpath_url: "user href").and_return([user])
|
19
|
+
User.authenticate_with_stormpath(username: 'username', password: "password").should == user
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return nil if authenticated on stormpath but no local user exists" do
|
23
|
+
Stormpath::Rails::Client.should_receive(:authenticate_account).with("username", "password").and_return(mock("account", get_href: "user href"))
|
24
|
+
User.should_receive(:where).with(stormpath_url: "user href").and_return([])
|
25
|
+
User.authenticate_with_stormpath(username: 'username', password: "password").should == nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return nil if stormpath authentication failed" do
|
29
|
+
Stormpath::Rails::Client.should_receive(:authenticate_account).with("username", "password").and_raise(ResourceError.new("Error"))
|
30
|
+
User.authenticate_with_stormpath(username: 'username', password: "password").should == nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-stormpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: devise
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: activesupport
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
|
-
type: :
|
54
|
+
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
@@ -59,6 +59,70 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 10.0.2
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 10.0.2
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.12.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.12.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: guard-rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.2.1
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.2.1
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rb-inotify
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.8.8
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.8.8
|
62
126
|
description: Devise extension to allow authentication via Stormpath
|
63
127
|
email: liquidautumn@gmail.com
|
64
128
|
executables: []
|
@@ -66,7 +130,9 @@ extensions: []
|
|
66
130
|
extra_rdoc_files: []
|
67
131
|
files:
|
68
132
|
- .gitignore
|
133
|
+
- .rspec
|
69
134
|
- Gemfile
|
135
|
+
- Guardfile
|
70
136
|
- LICENSE
|
71
137
|
- README.md
|
72
138
|
- Rakefile
|
@@ -75,7 +141,10 @@ files:
|
|
75
141
|
- lib/devise/stormpath/model.rb
|
76
142
|
- lib/devise/stormpath/strategy.rb
|
77
143
|
- lib/devise/stormpath/version.rb
|
78
|
-
|
144
|
+
- spec/devise/stormpath/model_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/support/client.rb
|
147
|
+
homepage:
|
79
148
|
licenses: []
|
80
149
|
post_install_message:
|
81
150
|
rdoc_options: []
|
@@ -87,18 +156,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
156
|
- - ! '>='
|
88
157
|
- !ruby/object:Gem::Version
|
89
158
|
version: '0'
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
hash: -1340532585845466111
|
93
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
160
|
none: false
|
95
161
|
requirements:
|
96
162
|
- - ! '>='
|
97
163
|
- !ruby/object:Gem::Version
|
98
164
|
version: '0'
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
hash: -1340532585845466111
|
102
165
|
requirements: []
|
103
166
|
rubyforge_project:
|
104
167
|
rubygems_version: 1.8.24
|