rockauth 0.0.1.pre2

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.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +30 -0
  4. data/app/admin/authentication.rb +37 -0
  5. data/app/admin/provider_authentications.rb +24 -0
  6. data/app/admin/resource_owner.rb +79 -0
  7. data/app/controllers/rockauth/authentications_controller.rb +48 -0
  8. data/app/controllers/rockauth/me_controller.rb +93 -0
  9. data/app/controllers/rockauth/provider_authentications_controller.rb +72 -0
  10. data/app/helpers/rockauth/application_helper.rb +4 -0
  11. data/app/models/rockauth/authentication.rb +6 -0
  12. data/app/models/rockauth/provider_authentication.rb +9 -0
  13. data/app/models/rockauth/user.rb +10 -0
  14. data/app/serializers/rockauth/authentication_serializer.rb +24 -0
  15. data/app/serializers/rockauth/base_serializer.rb +6 -0
  16. data/app/serializers/rockauth/error_serializer.rb +5 -0
  17. data/app/serializers/rockauth/provider_authentication_serializer.rb +5 -0
  18. data/app/serializers/rockauth/user_serializer.rb +23 -0
  19. data/app/views/layouts/rockauth/application.html.erb +14 -0
  20. data/config/locales/en.yml +12 -0
  21. data/config/routes.rb +9 -0
  22. data/db/migrate/20150709065335_create_rockauth_users.rb +16 -0
  23. data/db/migrate/20150709071113_create_rockauth_provider_authentications.rb +16 -0
  24. data/db/migrate/20150709084233_create_rockauth_authentications.rb +23 -0
  25. data/lib/generators/rockauth/client_generator.rb +33 -0
  26. data/lib/generators/rockauth/install_generator.rb +59 -0
  27. data/lib/generators/rockauth/migrations_generator.rb +9 -0
  28. data/lib/generators/rockauth/models_generator.rb +11 -0
  29. data/lib/generators/templates/authentication.rb +4 -0
  30. data/lib/generators/templates/provider_authentication.rb +5 -0
  31. data/lib/generators/templates/rockauth_clients.yml +9 -0
  32. data/lib/generators/templates/rockauth_full_initializer.rb +41 -0
  33. data/lib/generators/templates/rockauth_providers.json +50 -0
  34. data/lib/generators/templates/user.rb +7 -0
  35. data/lib/rockauth.rb +15 -0
  36. data/lib/rockauth/authenticator.rb +51 -0
  37. data/lib/rockauth/authenticator/response.rb +32 -0
  38. data/lib/rockauth/client.rb +4 -0
  39. data/lib/rockauth/configuration.rb +51 -0
  40. data/lib/rockauth/controllers.rb +5 -0
  41. data/lib/rockauth/controllers/authentication.rb +36 -0
  42. data/lib/rockauth/engine.rb +15 -0
  43. data/lib/rockauth/errors.rb +18 -0
  44. data/lib/rockauth/models.rb +9 -0
  45. data/lib/rockauth/models/authentication.rb +151 -0
  46. data/lib/rockauth/models/provider_authentication.rb +59 -0
  47. data/lib/rockauth/models/provider_validation.rb +61 -0
  48. data/lib/rockauth/models/resource_owner.rb +31 -0
  49. data/lib/rockauth/models/user.rb +25 -0
  50. data/lib/rockauth/provider_user_information.rb +103 -0
  51. data/lib/rockauth/version.rb +3 -0
  52. data/lib/tasks/rockauth_tasks.rake +9 -0
  53. metadata +361 -0
@@ -0,0 +1,31 @@
1
+ module Rockauth
2
+ module Models::ResourceOwner
3
+ extend ActiveSupport::Concern
4
+
5
+ def assign_attributes_from_provider_user provider_user_information
6
+ end
7
+
8
+ module ClassMethods
9
+ def resource_owner nested_attributes: true, validations: true, authentication_class_name: 'Rockauth::Authentication', provider_authentication_class_name: 'Rockauth::ProviderAuthentication'
10
+ @authentication_class_name = authentication_class_name
11
+ @provider_authentication_class_name = provider_authentication_class_name
12
+ has_many :provider_authentications, as: :resource_owner, inverse_of: :resource_owner, class_name: @provider_authentication_class_name, dependent: :destroy
13
+ has_many :authentications, as: :resource_owner, inverse_of: :resource_owner, class_name: @authentication_class_name, dependent: :destroy
14
+
15
+ accepts_nested_attributes_for :authentications
16
+ accepts_nested_attributes_for :provider_authentications
17
+
18
+ validates_associated :authentications, on: :create
19
+ # validates_presence_of :authentications, on: :create
20
+
21
+ def authentication_class
22
+ @authentication_class_name.safe_constantize
23
+ end
24
+
25
+ def provider_authentication_class
26
+ @provider_authentication_class_name.safe_constantize
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module Rockauth
2
+ module Models::User
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ validates_presence_of :email, if: :email_required?
7
+ validates_uniqueness_of :email, case_sensitive: false, allow_nil: true
8
+ validates_format_of :email, with: /\A[^@\s]+@([^@\s]+\.)+[^@\W]+\z/, if: -> { (new_record? || email_changed?) }, allow_blank: true
9
+
10
+ has_secure_password validations: false
11
+ validates_presence_of :password, if: :password_required?
12
+ validates_length_of :password, in: Configuration.allowed_password_length, allow_nil: true, allow_blank: true
13
+
14
+ scope :with_username, -> (username) { where("#{self.table_name}.email ILIKE ?", username) }
15
+
16
+ define_method :email_required? do
17
+ new_record? && provider_authentications.empty?
18
+ end
19
+
20
+ define_method :password_required? do
21
+ new_record? && provider_authentications.empty?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,103 @@
1
+ module Rockauth
2
+ class ProviderUserInformation < Struct.new(:access_token, :access_token_secret)
3
+ def self.for_provider provider, access_token, access_token_secret
4
+ klass = "#{self}::#{provider.to_s.camelize}".constantize
5
+ klass.new(access_token, access_token_secret)
6
+ end
7
+
8
+ def valid?
9
+ user_id.present?
10
+ end
11
+
12
+ def user
13
+ @user ||= begin
14
+ get_user
15
+ rescue StandardError => e
16
+ Rails.logger.error "[Rockauth] Could not authenticate social user: #{e}"
17
+ nil
18
+ end
19
+ end
20
+
21
+ def get_user
22
+ end
23
+
24
+ class Facebook < ProviderUserInformation
25
+ def user_id
26
+ user.try(:identifier)
27
+ end
28
+
29
+ def picture_url
30
+ user.picture :large
31
+ end
32
+
33
+ def get_user
34
+ FbGraph2::User.me(access_token).fetch
35
+ end
36
+ end
37
+
38
+ class Twitter < ProviderUserInformation
39
+ def user_id
40
+ user.try(:id)
41
+ end
42
+
43
+ def picture_url
44
+ user.profile_image_url_https(:bigger).to_s
45
+ end
46
+
47
+ def get_user
48
+ twitter_client.verify_credentials(skip_status: 1)
49
+ end
50
+
51
+ private
52
+
53
+ def twitter_client
54
+ @twitter_client ||= ::Twitter::REST::Client.new do |config|
55
+ config.consumer_key = Configuration.providers.twitter[:consumer_key]
56
+ config.consumer_secret = Configuration.providers.twitter[:consumer_secret]
57
+ config.access_token = access_token
58
+ config.access_token_secret = access_token_secret
59
+ end
60
+ end
61
+ end
62
+
63
+ class GooglePlus < ProviderUserInformation
64
+ def user_id
65
+ user[:sub]
66
+ end
67
+
68
+ # TODO: Implement a way of retreiving profile picture from google.
69
+ def picture_url
70
+ {}
71
+ end
72
+
73
+ def get_user
74
+ content = nil
75
+
76
+ uri = URI.parse('https://www.googleapis.com/oauth2/v3/tokeninfo')
77
+ uri.query = { id_token: access_token }.to_param
78
+
79
+ open(uri) do |f|
80
+ content = f.read
81
+ end
82
+
83
+ JSON.load(content).with_indifferent_access
84
+ end
85
+ end
86
+
87
+
88
+ class Instagram < ProviderUserInformation
89
+ def user_id
90
+ user.try(:id)
91
+ end
92
+
93
+ def picture_url
94
+ user.try(:profile_picture)
95
+ end
96
+
97
+ def get_user
98
+ ::Instagram.client(access_token: access_token).user
99
+ end
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,3 @@
1
+ module Rockauth
2
+ VERSION = "0.0.1.pre2"
3
+ end
@@ -0,0 +1,9 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rockauth do
3
+ # # Task goes here
4
+ # end
5
+
6
+
7
+ namespace :rockauth do
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,361 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rockauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre2
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: active_model_serializers
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bcrypt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.10
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.10
69
+ - !ruby/object:Gem::Dependency
70
+ name: jwt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: database_cleaner
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: shoulda-matchers
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.8.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.8.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: factory_girl_rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: faker
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: twitter
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: fb_graph2
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: instagram
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: webmock
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: timecop
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: activeadmin
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: pry-rails
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ description: An opinionated API Token Authentication mechanism.
280
+ email:
281
+ - evans.daniel.n@gmail.com
282
+ executables: []
283
+ extensions: []
284
+ extra_rdoc_files: []
285
+ files:
286
+ - MIT-LICENSE
287
+ - Rakefile
288
+ - app/admin/authentication.rb
289
+ - app/admin/provider_authentications.rb
290
+ - app/admin/resource_owner.rb
291
+ - app/controllers/rockauth/authentications_controller.rb
292
+ - app/controllers/rockauth/me_controller.rb
293
+ - app/controllers/rockauth/provider_authentications_controller.rb
294
+ - app/helpers/rockauth/application_helper.rb
295
+ - app/models/rockauth/authentication.rb
296
+ - app/models/rockauth/provider_authentication.rb
297
+ - app/models/rockauth/user.rb
298
+ - app/serializers/rockauth/authentication_serializer.rb
299
+ - app/serializers/rockauth/base_serializer.rb
300
+ - app/serializers/rockauth/error_serializer.rb
301
+ - app/serializers/rockauth/provider_authentication_serializer.rb
302
+ - app/serializers/rockauth/user_serializer.rb
303
+ - app/views/layouts/rockauth/application.html.erb
304
+ - config/locales/en.yml
305
+ - config/routes.rb
306
+ - db/migrate/20150709065335_create_rockauth_users.rb
307
+ - db/migrate/20150709071113_create_rockauth_provider_authentications.rb
308
+ - db/migrate/20150709084233_create_rockauth_authentications.rb
309
+ - lib/generators/rockauth/client_generator.rb
310
+ - lib/generators/rockauth/install_generator.rb
311
+ - lib/generators/rockauth/migrations_generator.rb
312
+ - lib/generators/rockauth/models_generator.rb
313
+ - lib/generators/templates/authentication.rb
314
+ - lib/generators/templates/provider_authentication.rb
315
+ - lib/generators/templates/rockauth_clients.yml
316
+ - lib/generators/templates/rockauth_full_initializer.rb
317
+ - lib/generators/templates/rockauth_providers.json
318
+ - lib/generators/templates/user.rb
319
+ - lib/rockauth.rb
320
+ - lib/rockauth/authenticator.rb
321
+ - lib/rockauth/authenticator/response.rb
322
+ - lib/rockauth/client.rb
323
+ - lib/rockauth/configuration.rb
324
+ - lib/rockauth/controllers.rb
325
+ - lib/rockauth/controllers/authentication.rb
326
+ - lib/rockauth/engine.rb
327
+ - lib/rockauth/errors.rb
328
+ - lib/rockauth/models.rb
329
+ - lib/rockauth/models/authentication.rb
330
+ - lib/rockauth/models/provider_authentication.rb
331
+ - lib/rockauth/models/provider_validation.rb
332
+ - lib/rockauth/models/resource_owner.rb
333
+ - lib/rockauth/models/user.rb
334
+ - lib/rockauth/provider_user_information.rb
335
+ - lib/rockauth/version.rb
336
+ - lib/tasks/rockauth_tasks.rake
337
+ homepage: https://github.com/rocketmade/rockauth
338
+ licenses:
339
+ - MIT
340
+ metadata: {}
341
+ post_install_message:
342
+ rdoc_options: []
343
+ require_paths:
344
+ - lib
345
+ required_ruby_version: !ruby/object:Gem::Requirement
346
+ requirements:
347
+ - - ">="
348
+ - !ruby/object:Gem::Version
349
+ version: '0'
350
+ required_rubygems_version: !ruby/object:Gem::Requirement
351
+ requirements:
352
+ - - ">"
353
+ - !ruby/object:Gem::Version
354
+ version: 1.3.1
355
+ requirements: []
356
+ rubyforge_project:
357
+ rubygems_version: 2.4.5.1
358
+ signing_key:
359
+ specification_version: 4
360
+ summary: An opinionated API Token Authentication mechanism.
361
+ test_files: []