thincloud-authentication 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -140,12 +140,12 @@ Using the example above, you will have the following routes locally:
140
140
 
141
141
  ### Redirection
142
142
 
143
- You can customize the paths used to redirect users after login, logout and registration by overriding the corresponding methods in your ApplicationController, or specific controllers, as needed.
143
+ You can customize the paths used to redirect users after login, logout, registration and email verification by overriding the corresponding methods in your ApplicationController, or specific controllers, as needed.
144
144
 
145
145
  * `after_login_path` is used after the user logs in.
146
146
  * `after_logout_path` is used after the user logs out.
147
147
  * `after_registration_path` is used after the user registers.
148
-
148
+ * `after_verification_path` is used after the user verifies their email.
149
149
 
150
150
  ## TODO
151
151
 
@@ -1,10 +1,12 @@
1
- require_dependency "thincloud/authentication/application_controller"
2
-
3
1
  module Thincloud::Authentication
4
2
  # Public: Handle OmniAuth callbacks.
5
3
  class RegistrationsController < ApplicationController
6
4
  before_filter :extract_identity, only: :create
7
5
 
6
+ layout Thincloud::Authentication.configuration.layout
7
+
8
+ helper "thincloud/authentication/registrations"
9
+
8
10
  def new
9
11
  @identity = Identity.new
10
12
  end
@@ -13,11 +15,11 @@ module Thincloud::Authentication
13
15
  # identity exists
14
16
  if @identity.present?
15
17
  login_as @identity.user
16
- redirect_to main_app.root_url, notice: "You have been logged in."
18
+ redirect_to after_login_path, notice: "You have been logged in."
17
19
  # new identity for current_user
18
20
  elsif current_user
19
21
  add_omniauth_identity_to_current_user
20
- redirect_to main_app.root_url, notice: "You have been logged in."
22
+ redirect_to after_login_path, notice: "You have been logged in."
21
23
  # failed identity login
22
24
  elsif invalid_identity_credentials?
23
25
  redirect_to auth_failure_url message: "invalid_credentials",
@@ -40,7 +42,7 @@ module Thincloud::Authentication
40
42
  def verify
41
43
  identity = Identity.verify!(params[:token])
42
44
  login_as identity.user
43
- redirect_to main_app.root_url,
45
+ redirect_to after_verification_path,
44
46
  notice: "Thank you! Your registration has been verified."
45
47
  end
46
48
 
@@ -79,12 +81,23 @@ module Thincloud::Authentication
79
81
  # Returns: An instance of `Identity`.
80
82
  def create_identity_from_request
81
83
  # params[:identity] exists when creating a local identity provider
82
- Identity.new(params[:identity]).tap do |identity|
84
+ Identity.new(identity_params).tap do |identity|
83
85
  identity.user = User.create
84
86
  # omniauth exists if coming from a 3rd party provider like LinkedIn
85
87
  identity.apply_omniauth(omniauth) if omniauth
86
88
  identity.save
87
89
  end
88
90
  end
91
+
92
+ # Private: Provide strong_parameters support
93
+ # :token, :auth_key, :provider,
94
+ def identity_params
95
+ keys = [
96
+ :name, :email, :password,
97
+ :password_confirmation, :verification_token
98
+ ]
99
+
100
+ params.require(:identity).permit(*keys)
101
+ end
89
102
  end
90
103
  end
@@ -1,10 +1,12 @@
1
- require_dependency "thincloud/authentication/application_controller"
2
-
3
1
  module Thincloud::Authentication
4
2
  # Public: Handle login/logout behavior.
5
3
  class SessionsController < ApplicationController
6
4
  before_filter :authenticate!, only: [:authenticated]
7
5
 
6
+ layout Thincloud::Authentication.configuration.layout
7
+
8
+ helper "thincloud/authentication/registrations"
9
+
8
10
  def new
9
11
  redirect_to after_login_path if logged_in?
10
12
  @identity = Identity.new
@@ -1,6 +1,8 @@
1
1
  module Thincloud::Authentication
2
2
  # Public: This class represents a User identity (name, email, login provider)
3
3
  class Identity < ::OmniAuth::Identity::Models::ActiveRecord
4
+ include ActiveModel::ForbiddenAttributesProtection # strong_parameters
5
+
4
6
  belongs_to :user
5
7
 
6
8
  # Limit the ability to mass-assign sensitive fields.
@@ -30,7 +32,9 @@ module Thincloud::Authentication
30
32
  #
31
33
  # Returns: An instance of `Identity` or `nil`.
32
34
  def self.find_omniauth(omniauth)
33
- find_by_provider_and_uid omniauth["provider"], omniauth["uid"]
35
+ if omniauth["uid"].present?
36
+ find_by_provider_and_uid omniauth["provider"], omniauth["uid"]
37
+ end
34
38
  end
35
39
 
36
40
  # Public: Mark the `Identity` as having been verified.
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  Thincloud::Authentication::Engine.routes.draw do
2
- match ":provider/callback" => "registrations#create", as: "auth_callback"
2
+ post ":provider/callback", to: "registrations#create", as: "auth_callback"
3
3
  get "failure", to: "sessions#new", as: "auth_failure"
4
4
 
5
5
  get "login", to: "sessions#new", as: "login"
@@ -79,6 +79,14 @@ module Thincloud
79
79
  main_app.root_url
80
80
  end
81
81
 
82
+ # Protected: Provides the URL to redirect to after verification.
83
+ #
84
+ # Returns: A string.
85
+ def after_verification_path
86
+ main_app.root_url
87
+ end
88
+
89
+
82
90
  end
83
91
 
84
92
  end
@@ -1,17 +1,25 @@
1
1
  module Thincloud
2
2
  module Authentication
3
+
3
4
  # Public: Initialize the Rails engine
4
5
  class Engine < ::Rails::Engine
5
6
  isolate_namespace Thincloud::Authentication
6
7
 
8
+ require "thincloud/authentication/configuration"
9
+
10
+ initializer "thincloud.authentication.require_dependencies" do
11
+ require_dependency "thincloud/authentication/authenticatable_controller"
12
+ require_dependency "thincloud/authentication/identifiable_user"
13
+ end
14
+
7
15
  initializer "thincloud.authentication.omniauth.middleware" do |app|
8
16
  require "omniauth"
9
17
  require "omniauth-identity"
10
18
 
11
- config = Thincloud::Authentication.configuration || Configuration.new
12
- strategies = config.providers.keys
19
+ conf = Thincloud::Authentication.configuration || Configuration.new
20
+ strategies = conf.providers.keys
13
21
  strategies.each do |strategy|
14
- lib = config.providers[strategy][:require] || "omniauth-#{strategy}"
22
+ lib = conf.providers[strategy][:require] || "omniauth-#{strategy}"
15
23
  require lib
16
24
  end
17
25
 
@@ -23,8 +31,8 @@ module Thincloud
23
31
  strategies.each do |strategy|
24
32
  provider strategy, ENV["#{strategy.to_s.upcase}_CONSUMER_KEY"],
25
33
  ENV["#{strategy.to_s.upcase}_CONSUMER_SECRET"],
26
- fields: config.providers[strategy][:fields],
27
- scope: config.providers[strategy][:scopes]
34
+ fields: conf.providers[strategy][:fields],
35
+ scope: conf.providers[strategy][:scopes]
28
36
  end
29
37
  end
30
38
  end
@@ -53,12 +61,16 @@ module Thincloud
53
61
  end
54
62
 
55
63
  initializer "thincloud.authentication.user" do
56
- ::User.send :include, Thincloud::Authentication::IdentifiableUser
64
+ config.to_prepare do
65
+ ::User.send :include, Thincloud::Authentication::IdentifiableUser
66
+ end
57
67
  end
58
68
 
59
69
  initializer "thincloud.authentication.action_controller" do
60
- ActionController::Base.send :include,
61
- Thincloud::Authentication::AuthenticatableController
70
+ config.to_prepare do
71
+ ActionController::Base.send :include,
72
+ Thincloud::Authentication::AuthenticatableController
73
+ end
62
74
  end
63
75
 
64
76
  config.generators do |g|
@@ -1,5 +1,5 @@
1
1
  module Thincloud
2
2
  module Authentication
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -1,7 +1,4 @@
1
- require "thincloud/authentication/configuration"
2
1
  require "thincloud/authentication/engine"
3
- require "thincloud/authentication/authenticatable_controller"
4
- require "thincloud/authentication/identifiable_user"
5
2
 
6
3
  module Thincloud
7
4
  module Authentication
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thincloud-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-14 00:00:00.000000000 Z
13
+ date: 2013-04-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 3.2.8
22
+ version: 3.2.13
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,128 +27,16 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 3.2.8
30
+ version: 3.2.13
31
31
  - !ruby/object:Gem::Dependency
32
- name: omniauth
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ~>
37
- - !ruby/object:Gem::Version
38
- version: 1.1.1
39
- type: :runtime
40
- prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ~>
45
- - !ruby/object:Gem::Version
46
- version: 1.1.1
47
- - !ruby/object:Gem::Dependency
48
- name: omniauth-identity
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 1.1.0
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: 1.1.0
63
- - !ruby/object:Gem::Dependency
64
- name: cane
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ~>
69
- - !ruby/object:Gem::Version
70
- version: 2.3.0
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ~>
77
- - !ruby/object:Gem::Version
78
- version: 2.3.0
79
- - !ruby/object:Gem::Dependency
80
- name: guard
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ~>
85
- - !ruby/object:Gem::Version
86
- version: 1.4.0
87
- type: :development
88
- prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ~>
93
- - !ruby/object:Gem::Version
94
- version: 1.4.0
95
- - !ruby/object:Gem::Dependency
96
- name: minitest
97
- requirement: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ~>
101
- - !ruby/object:Gem::Version
102
- version: 3.4.0
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: 3.4.0
111
- - !ruby/object:Gem::Dependency
112
- name: guard-minitest
113
- requirement: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ~>
117
- - !ruby/object:Gem::Version
118
- version: 0.5.0
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ~>
125
- - !ruby/object:Gem::Version
126
- version: 0.5.0
127
- - !ruby/object:Gem::Dependency
128
- name: minitest-rails
129
- requirement: !ruby/object:Gem::Requirement
130
- none: false
131
- requirements:
132
- - - ~>
133
- - !ruby/object:Gem::Version
134
- version: 0.2.0
135
- type: :development
136
- prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ~>
141
- - !ruby/object:Gem::Version
142
- version: 0.2.0
143
- - !ruby/object:Gem::Dependency
144
- name: minitest-rails-shoulda
32
+ name: strong_parameters
145
33
  requirement: !ruby/object:Gem::Requirement
146
34
  none: false
147
35
  requirements:
148
36
  - - ~>
149
37
  - !ruby/object:Gem::Version
150
38
  version: 0.2.0
151
- type: :development
39
+ type: :runtime
152
40
  prerelease: false
153
41
  version_requirements: !ruby/object:Gem::Requirement
154
42
  none: false
@@ -157,45 +45,45 @@ dependencies:
157
45
  - !ruby/object:Gem::Version
158
46
  version: 0.2.0
159
47
  - !ruby/object:Gem::Dependency
160
- name: rb-fsevent
48
+ name: omniauth
161
49
  requirement: !ruby/object:Gem::Requirement
162
50
  none: false
163
51
  requirements:
164
52
  - - ~>
165
53
  - !ruby/object:Gem::Version
166
- version: 0.9.1
167
- type: :development
54
+ version: 1.1.3
55
+ type: :runtime
168
56
  prerelease: false
169
57
  version_requirements: !ruby/object:Gem::Requirement
170
58
  none: false
171
59
  requirements:
172
60
  - - ~>
173
61
  - !ruby/object:Gem::Version
174
- version: 0.9.1
62
+ version: 1.1.3
175
63
  - !ruby/object:Gem::Dependency
176
- name: simplecov
64
+ name: omniauth-identity
177
65
  requirement: !ruby/object:Gem::Requirement
178
66
  none: false
179
67
  requirements:
180
68
  - - ~>
181
69
  - !ruby/object:Gem::Version
182
- version: 0.7.1
183
- type: :development
70
+ version: 1.1.0
71
+ type: :runtime
184
72
  prerelease: false
185
73
  version_requirements: !ruby/object:Gem::Requirement
186
74
  none: false
187
75
  requirements:
188
76
  - - ~>
189
77
  - !ruby/object:Gem::Version
190
- version: 0.7.1
78
+ version: 1.1.0
191
79
  - !ruby/object:Gem::Dependency
192
- name: mocha
80
+ name: thincloud-test-rails
193
81
  requirement: !ruby/object:Gem::Requirement
194
82
  none: false
195
83
  requirements:
196
84
  - - ~>
197
85
  - !ruby/object:Gem::Version
198
- version: 0.12.7
86
+ version: 1.0.0
199
87
  type: :development
200
88
  prerelease: false
201
89
  version_requirements: !ruby/object:Gem::Requirement
@@ -203,7 +91,7 @@ dependencies:
203
91
  requirements:
204
92
  - - ~>
205
93
  - !ruby/object:Gem::Version
206
- version: 0.12.7
94
+ version: 1.0.0
207
95
  description: Rails Engine to provide authentication for Thincloud applications
208
96
  email:
209
97
  - pcohen@newleaders.com
@@ -214,7 +102,6 @@ extra_rdoc_files: []
214
102
  files:
215
103
  - app/assets/javascripts/thincloud/authentication/application.js
216
104
  - app/assets/stylesheets/thincloud/authentication/application.css
217
- - app/controllers/thincloud/authentication/application_controller.rb
218
105
  - app/controllers/thincloud/authentication/registrations_controller.rb
219
106
  - app/controllers/thincloud/authentication/sessions_controller.rb
220
107
  - app/helpers/thincloud/authentication/registrations_helper.rb
@@ -252,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
139
  version: '0'
253
140
  segments:
254
141
  - 0
255
- hash: -3024527014021950158
142
+ hash: 4510440857469135512
256
143
  required_rubygems_version: !ruby/object:Gem::Requirement
257
144
  none: false
258
145
  requirements:
@@ -261,10 +148,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
148
  version: '0'
262
149
  segments:
263
150
  - 0
264
- hash: -3024527014021950158
151
+ hash: 4510440857469135512
265
152
  requirements: []
266
153
  rubyforge_project:
267
- rubygems_version: 1.8.24
154
+ rubygems_version: 1.8.25
268
155
  signing_key:
269
156
  specification_version: 3
270
157
  summary: Rails Engine to provide authentication for Thincloud applications
@@ -1,6 +0,0 @@
1
- module Thincloud::Authentication
2
- # Public: Primary controller settings and helpers for the engine.
3
- class ApplicationController < ActionController::Base
4
- layout Thincloud::Authentication.configuration.layout
5
- end
6
- end