rockauth 0.0.1.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +30 -0
- data/app/admin/authentication.rb +37 -0
- data/app/admin/provider_authentications.rb +24 -0
- data/app/admin/resource_owner.rb +79 -0
- data/app/controllers/rockauth/authentications_controller.rb +48 -0
- data/app/controllers/rockauth/me_controller.rb +93 -0
- data/app/controllers/rockauth/provider_authentications_controller.rb +72 -0
- data/app/helpers/rockauth/application_helper.rb +4 -0
- data/app/models/rockauth/authentication.rb +6 -0
- data/app/models/rockauth/provider_authentication.rb +9 -0
- data/app/models/rockauth/user.rb +10 -0
- data/app/serializers/rockauth/authentication_serializer.rb +24 -0
- data/app/serializers/rockauth/base_serializer.rb +6 -0
- data/app/serializers/rockauth/error_serializer.rb +5 -0
- data/app/serializers/rockauth/provider_authentication_serializer.rb +5 -0
- data/app/serializers/rockauth/user_serializer.rb +23 -0
- data/app/views/layouts/rockauth/application.html.erb +14 -0
- data/config/locales/en.yml +12 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20150709065335_create_rockauth_users.rb +16 -0
- data/db/migrate/20150709071113_create_rockauth_provider_authentications.rb +16 -0
- data/db/migrate/20150709084233_create_rockauth_authentications.rb +23 -0
- data/lib/generators/rockauth/client_generator.rb +33 -0
- data/lib/generators/rockauth/install_generator.rb +59 -0
- data/lib/generators/rockauth/migrations_generator.rb +9 -0
- data/lib/generators/rockauth/models_generator.rb +11 -0
- data/lib/generators/templates/authentication.rb +4 -0
- data/lib/generators/templates/provider_authentication.rb +5 -0
- data/lib/generators/templates/rockauth_clients.yml +9 -0
- data/lib/generators/templates/rockauth_full_initializer.rb +41 -0
- data/lib/generators/templates/rockauth_providers.json +50 -0
- data/lib/generators/templates/user.rb +7 -0
- data/lib/rockauth.rb +15 -0
- data/lib/rockauth/authenticator.rb +51 -0
- data/lib/rockauth/authenticator/response.rb +32 -0
- data/lib/rockauth/client.rb +4 -0
- data/lib/rockauth/configuration.rb +51 -0
- data/lib/rockauth/controllers.rb +5 -0
- data/lib/rockauth/controllers/authentication.rb +36 -0
- data/lib/rockauth/engine.rb +15 -0
- data/lib/rockauth/errors.rb +18 -0
- data/lib/rockauth/models.rb +9 -0
- data/lib/rockauth/models/authentication.rb +151 -0
- data/lib/rockauth/models/provider_authentication.rb +59 -0
- data/lib/rockauth/models/provider_validation.rb +61 -0
- data/lib/rockauth/models/resource_owner.rb +31 -0
- data/lib/rockauth/models/user.rb +25 -0
- data/lib/rockauth/provider_user_information.rb +103 -0
- data/lib/rockauth/version.rb +3 -0
- data/lib/tasks/rockauth_tasks.rake +9 -0
- metadata +361 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31e30da292055c2bc8aa2a92d48d19161dd1cede
|
4
|
+
data.tar.gz: 472cacd4d60479a7e303461bf45a96c6307a893d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 622b00715c2f6bfb1181e52e5ff3d6ff7a6fdd5306bfde468b00187cad4e929e47d93e66b1d328ceef29d5612a2904cb53ffdbac04d4e7be4a04807e3bc7c86b
|
7
|
+
data.tar.gz: d4533658991b8abbe39a5dc747b436d6df9bc349594ddac4d8a9e3722c338878e55f8930b3fce095f1c9a845a35b522f62f45165c726b2bbe547d8fbc095a04d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Daniel Evans
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Rockauth'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
|
19
|
+
load 'rails/tasks/engine.rake'
|
20
|
+
|
21
|
+
Bundler::GemHelper.install_tasks
|
22
|
+
|
23
|
+
require 'rake'
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
|
26
|
+
desc "Run all examples"
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
28
|
+
end
|
29
|
+
|
30
|
+
task default: %i(spec)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
ActiveAdmin.register Rockauth::Configuration.resource_owner_class.reflections['authentications'].klass, as: "Authentication" do
|
2
|
+
menu parent: Rockauth::Configuration.active_admin_menu_name
|
3
|
+
|
4
|
+
actions :all, except: %i(new create edit update)
|
5
|
+
|
6
|
+
index do
|
7
|
+
id_column
|
8
|
+
column :auth_type
|
9
|
+
column :client
|
10
|
+
column :device_os
|
11
|
+
|
12
|
+
column :expiration do |r|
|
13
|
+
Time.at(r.expiration).to_formatted_s(:rfc822) if r.expiration.present?
|
14
|
+
end
|
15
|
+
|
16
|
+
column :issued_at do |r|
|
17
|
+
Time.at(r.issued_at).to_formatted_s(:rfc822) if r.issued_at.present?
|
18
|
+
end
|
19
|
+
actions
|
20
|
+
end
|
21
|
+
|
22
|
+
show do
|
23
|
+
attributes_table do
|
24
|
+
row :expiration do |r|
|
25
|
+
Time.at(r.expiration).to_formatted_s(:rfc822) if r.expiration.present?
|
26
|
+
end
|
27
|
+
|
28
|
+
row :issued_at do |r|
|
29
|
+
Time.at(r.issued_at).to_formatted_s(:rfc822) if r.issued_at.present?
|
30
|
+
end
|
31
|
+
(resource.attribute_names.map(&:to_sym) - %i(hashed_token_id expiration issued_at)).each do |key|
|
32
|
+
row key
|
33
|
+
end
|
34
|
+
end
|
35
|
+
active_admin_comments
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
ActiveAdmin.register Rockauth::Configuration.resource_owner_class.reflections['provider_authentications'].klass, as: "ProviderAuthentication" do
|
2
|
+
menu parent: Rockauth::Configuration.active_admin_menu_name
|
3
|
+
|
4
|
+
actions :all, except: %i(new create edit update)
|
5
|
+
|
6
|
+
|
7
|
+
index do
|
8
|
+
id_column
|
9
|
+
column :resource_owner
|
10
|
+
column :provider
|
11
|
+
column :provider_user_id
|
12
|
+
column :created_at
|
13
|
+
actions
|
14
|
+
end
|
15
|
+
|
16
|
+
show do
|
17
|
+
attributes_table do
|
18
|
+
(resource.attribute_names.map(&:to_sym) - %i(provider_access_token provider_access_token_secret)).each do |key|
|
19
|
+
row key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
active_admin_comments
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
ActiveAdmin.register Rockauth::Configuration.resource_owner_class, as: "User" do
|
2
|
+
menu parent: Rockauth::Configuration.active_admin_menu_name
|
3
|
+
|
4
|
+
controller do
|
5
|
+
helper_method :attribute_list
|
6
|
+
def attribute_list
|
7
|
+
(Rockauth::Configuration.resource_owner_class.attribute_names.map(&:to_sym) - %i(id password_digest created_at updated_at))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
permit_params do
|
12
|
+
(attribute_list + %i(password))
|
13
|
+
end
|
14
|
+
|
15
|
+
index do
|
16
|
+
id_column
|
17
|
+
((attribute_list & %i(email)) + %i(created_at)).each do |key|
|
18
|
+
column key
|
19
|
+
end
|
20
|
+
actions
|
21
|
+
end
|
22
|
+
|
23
|
+
show do
|
24
|
+
attributes_table do
|
25
|
+
(attribute_list + %i{created_at updated_at}).each do |key|
|
26
|
+
row key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
panel "Authentications" do
|
31
|
+
table_for resource.authentications do
|
32
|
+
column :id do |r|
|
33
|
+
link_to r.id, admin_user_path(r)
|
34
|
+
end
|
35
|
+
column :auth_type
|
36
|
+
column :client
|
37
|
+
column :device_os
|
38
|
+
|
39
|
+
column :expiration do |r|
|
40
|
+
Time.at(r.expiration).to_formatted_s(:rfc822) if r.expiration.present?
|
41
|
+
end
|
42
|
+
|
43
|
+
column :issued_at do |r|
|
44
|
+
Time.at(r.issued_at).to_formatted_s(:rfc822) if r.issued_at.present?
|
45
|
+
end
|
46
|
+
|
47
|
+
column do |r|
|
48
|
+
text_node link_to('View', admin_authentication_path(r), class: 'member_link')
|
49
|
+
text_node link_to('Destroy', admin_authentication_path(r), method: :delete, data: { confirm: 'Are you sure?' }, class: 'member_link')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
panel "Provider Authentications (social authorizations)" do
|
56
|
+
table_for resource.provider_authentications do
|
57
|
+
column :id do |r|
|
58
|
+
link_to r.id # link_to r.id, [:admin, r]
|
59
|
+
end
|
60
|
+
column :provider
|
61
|
+
column :provider_user_id
|
62
|
+
column :created_at
|
63
|
+
|
64
|
+
column do |r|
|
65
|
+
text_node link_to('View', admin_provider_authentication_path(r), class: 'member_link')
|
66
|
+
text_node link_to('Destroy', admin_provider_authentication_path(r), method: :delete, data: { confirm: 'Are you sure?' }, class: 'member_link')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
active_admin_comments
|
72
|
+
end
|
73
|
+
|
74
|
+
form do |f|
|
75
|
+
f.semantic_errors
|
76
|
+
f.inputs (attribute_list + %i(password))
|
77
|
+
f.actions
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rails-api'
|
2
|
+
require 'active_model_serializers'
|
3
|
+
|
4
|
+
module Rockauth
|
5
|
+
class AuthenticationsController < ActionController::API
|
6
|
+
include ActionController::Helpers
|
7
|
+
include ActionController::Serialization
|
8
|
+
|
9
|
+
serialization_scope :view_context
|
10
|
+
|
11
|
+
before_filter :authenticate_resource_owner!, except: [:authenticate]
|
12
|
+
|
13
|
+
def index
|
14
|
+
@authentications = current_resource_owner.authentications
|
15
|
+
render json: @authentications
|
16
|
+
end
|
17
|
+
|
18
|
+
def authenticate
|
19
|
+
@auth_response = Authenticator.authentication_request(request, self)
|
20
|
+
if @auth_response.success
|
21
|
+
@current_resource_owner = @auth_response.resource_owner
|
22
|
+
end
|
23
|
+
render @auth_response.render
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
record = current_authentication
|
28
|
+
record = current_resource_owner.authentications.find(params[:id]) if params[:id].present?
|
29
|
+
if record.destroy
|
30
|
+
render nothing: true, status: 200
|
31
|
+
else
|
32
|
+
render_error 409, I18n.t("rockauth.errors.destroy_error", resource: "Authentication")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def resource
|
37
|
+
@authentication
|
38
|
+
end
|
39
|
+
|
40
|
+
def authentication_options
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
|
44
|
+
def resource_owner_class
|
45
|
+
Rockauth::Configuration.resource_owner_class
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rails-api'
|
2
|
+
require 'active_model_serializers'
|
3
|
+
|
4
|
+
module Rockauth
|
5
|
+
class MeController < ActionController::API
|
6
|
+
include ActionController::Helpers
|
7
|
+
include ActionController::Serialization
|
8
|
+
|
9
|
+
before_filter :authenticate_resource_owner!, except: [:create]
|
10
|
+
|
11
|
+
helper_method :include_authentication?
|
12
|
+
|
13
|
+
serialization_scope :view_context
|
14
|
+
|
15
|
+
def create
|
16
|
+
build_resource
|
17
|
+
|
18
|
+
# Makes the UserSerializer work properly and display all probative data.
|
19
|
+
@current_resource_owner = resource
|
20
|
+
@current_authentication = resource.try(:authentication)
|
21
|
+
|
22
|
+
render_resource_or_error resource.save
|
23
|
+
end
|
24
|
+
|
25
|
+
def show
|
26
|
+
render_resource
|
27
|
+
end
|
28
|
+
|
29
|
+
def update
|
30
|
+
resource.assign_attributes permitted_params.fetch(:user, {})
|
31
|
+
render_resource_or_error resource.save
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
if resource.destroy
|
36
|
+
render nothing: true, status: 200
|
37
|
+
else
|
38
|
+
render_action_error 409
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_resource
|
43
|
+
render json: resource, status: 200
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_action_error error_status=400
|
47
|
+
render_error error_status, I18n.t("rockauth.errors.#{action_name}_error", resource: resource.class.model_name.human), resource.errors
|
48
|
+
end
|
49
|
+
|
50
|
+
def render_resource_or_error successful, error_status: 400
|
51
|
+
if successful
|
52
|
+
render_resource
|
53
|
+
else
|
54
|
+
render_action_error error_status
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def resource
|
61
|
+
@user ||= current_resource_owner
|
62
|
+
end
|
63
|
+
|
64
|
+
def permitted_params
|
65
|
+
permitted = params.permit(user: [*%i(email password first_name last_name),
|
66
|
+
provider_authentications: [:provider, :provider_access_token, :provider_access_token_secret],
|
67
|
+
authentication: [*%i(auth_type client_id client_secret client_version device_identifier device_description device_os device_os_version)]]).to_h.with_indifferent_access
|
68
|
+
user_params = permitted[:user] || {}
|
69
|
+
|
70
|
+
if action_name == 'update'
|
71
|
+
user_params.delete :authentication
|
72
|
+
else
|
73
|
+
user_params[:authentications_attributes] = [(user_params.delete(:authentication) || {}).merge(auth_type: 'registration')]
|
74
|
+
end
|
75
|
+
|
76
|
+
if user_params.has_key? :provider_authentications
|
77
|
+
user_params[:provider_authentications_attributes] = user_params.delete(:provider_authentications)
|
78
|
+
end
|
79
|
+
|
80
|
+
permitted
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_resource
|
84
|
+
@user = User.new.tap do |user|
|
85
|
+
user.assign_attributes permitted_params[:user]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def include_authentication?
|
90
|
+
action_name == 'create'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rails-api'
|
2
|
+
require 'active_model_serializers'
|
3
|
+
|
4
|
+
module Rockauth
|
5
|
+
class ProviderAuthenticationsController < ActionController::API
|
6
|
+
include ActionController::Helpers
|
7
|
+
include ActionController::Serialization
|
8
|
+
|
9
|
+
before_filter :authenticate_resource_owner!
|
10
|
+
serialization_scope :view_context
|
11
|
+
|
12
|
+
def index
|
13
|
+
render json: collection
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
build_resource
|
18
|
+
render_resource_or_error resource.save
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
render_resource
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
resource.assign_attributes permitted_params[:provider_authentication]
|
27
|
+
render_resource_or_error resource.save
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
if resource.destroy
|
32
|
+
render nothing: true, status: 200
|
33
|
+
else
|
34
|
+
render_action_error 409
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_resource
|
39
|
+
render json: resource, status: 200
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_action_error error_status=400
|
43
|
+
render_error error_status, I18n.t("rockauth.errors.#{action_name}_error", resource: resource.class.model_name.human), resource.errors
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_resource_or_error successful, error_status: 400
|
47
|
+
if successful
|
48
|
+
render_resource
|
49
|
+
else
|
50
|
+
render_action_error error_status
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
|
56
|
+
def resource
|
57
|
+
@provider_authentication ||= current_resource_owner.provider_authentications.find(params[:id])
|
58
|
+
end
|
59
|
+
|
60
|
+
def collection
|
61
|
+
@provider_authentications ||= current_resource_owner.provider_authentications
|
62
|
+
end
|
63
|
+
|
64
|
+
def permitted_params
|
65
|
+
params.permit(provider_authentication: %i{provider provider_access_token})
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_resource
|
69
|
+
@provider_authentication ||= current_resource_owner.provider_authentications.build permitted_params[:provider_authentication]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|