devise_castle 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/devise/devise_castle_controller.rb +0 -57
- data/lib/devise_castle.rb +2 -4
- data/lib/devise_castle/controllers/helpers.rb +0 -18
- data/lib/devise_castle/hooks.rb +1 -22
- data/lib/devise_castle/model.rb +1 -14
- data/lib/devise_castle/routes.rb +0 -1
- data/lib/devise_castle/version.rb +1 -1
- metadata +4 -15
- data/app/controllers/devise/two_factor_authentication_controller.rb +0 -3
- data/app/views/devise/two_factor_authentication/authenticator/edit.html.erb +0 -14
- data/app/views/devise/two_factor_authentication/sms/edit.html.erb +0 -17
- data/app/views/devise/two_factor_authentication/yubikey/edit.html.erb +0 -14
- data/lib/devise_castle/import.rb +0 -85
- data/lib/generators/active_record/devise_castle_generator.rb +0 -14
- data/lib/generators/active_record/templates/migration.rb +0 -13
- data/lib/generators/devise_castle/devise_castle_generator.rb +0 -18
- data/lib/generators/devise_castle/import_generator.rb +0 -12
- data/lib/generators/devise_castle/views_generator.rb +0 -18
- data/lib/generators/mongoid/devise_castle_generator.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80523e6589fed7b828f62fa4d08714082f4c2ea9
|
4
|
+
data.tar.gz: 6d102ea40c2ab3dc6256fe475087ebbd27abf99c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1825ede77b3cbd3d59334c8d9dbcdf65dec4c2ca350e433b147eec62eaad8c1be6f494b1093fd0e2b5870d03fadf8f11a5b5b3872b0a3f064ef17370abf1572
|
7
|
+
data.tar.gz: 6b3f7020957b48a990f129bf137ca1a304422f250555405ad59cd3c220f9ecd13cc63dc31636200307ca66ea0ce1a7933d2bdecfd7fa98868b46a624db83a789
|
@@ -1,60 +1,3 @@
|
|
1
1
|
class Devise::DeviseCastleController < DeviseController
|
2
2
|
include Devise::Controllers::Helpers
|
3
|
-
|
4
|
-
before_filter :return_not_found, except: :new
|
5
|
-
|
6
|
-
before_filter do
|
7
|
-
env['castle.skip_authorization'] = true
|
8
|
-
end
|
9
|
-
|
10
|
-
def new
|
11
|
-
challenge = castle.challenges.create
|
12
|
-
Devise.mappings.keys.flatten.any? do |scope|
|
13
|
-
redirect_to send(
|
14
|
-
"edit_#{scope}_two_factor_authentication_path", challenge.id)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def edit
|
19
|
-
@challenge = castle.challenges.find(params[:id])
|
20
|
-
|
21
|
-
# Prevent "undefined method `errors' for nil:NilClass"
|
22
|
-
self.resource = resource_class.new
|
23
|
-
|
24
|
-
render action: "#{@challenge.delivery_method}/edit"
|
25
|
-
end
|
26
|
-
|
27
|
-
def update
|
28
|
-
challenge_id = params.require(:challenge_id)
|
29
|
-
code = params.require(:code)
|
30
|
-
|
31
|
-
begin
|
32
|
-
castle.challenges.verify(challenge_id, response: code)
|
33
|
-
|
34
|
-
castle.trust_device if params[:trust_device]
|
35
|
-
|
36
|
-
Devise.mappings.keys.flatten.any? do |scope|
|
37
|
-
redirect_to after_sign_in_path_for(scope)
|
38
|
-
end
|
39
|
-
rescue Castle::Error
|
40
|
-
sign_out_with_message(:no_retries_remaining, :alert)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
protected
|
45
|
-
|
46
|
-
def sign_out_with_message(message, kind = :notice)
|
47
|
-
signed_out = sign_out(resource_name)
|
48
|
-
set_flash_message kind, message if signed_out
|
49
|
-
redirect_to after_sign_out_path_for(resource_name)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def return_not_found
|
55
|
-
unless castle.mfa_in_progress?
|
56
|
-
redirect_to after_sign_in_path_for(resource_name)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
3
|
end
|
data/lib/devise_castle.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
require 'devise'
|
3
3
|
require 'devise_castle/hooks'
|
4
|
-
require 'devise_castle/routes'
|
5
|
-
require 'devise_castle/hooks'
|
6
|
-
require 'devise_castle/import'
|
7
4
|
require 'devise_castle/mapping'
|
5
|
+
require 'devise_castle/routes'
|
8
6
|
require 'castle-rb'
|
9
7
|
|
10
8
|
module Devise
|
@@ -24,6 +22,6 @@ if defined?(Rails::Railtie)
|
|
24
22
|
end
|
25
23
|
|
26
24
|
Devise.add_module(:castle,
|
27
|
-
:controller => :
|
25
|
+
:controller => :devise_castle,
|
28
26
|
:route => :castle,
|
29
27
|
:model => 'devise_castle/model')
|
@@ -4,24 +4,6 @@ module DeviseCastle
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
rescue_from Castle::UserUnauthorizedError do |error|
|
8
|
-
Devise.mappings.keys.flatten.any? do |scope|
|
9
|
-
warden.logout(scope)
|
10
|
-
throw :warden, :scope => scope, :message => :signed_out
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
rescue_from Castle::ChallengeRequiredError do |error|
|
15
|
-
Devise.mappings.keys.flatten.any? do |scope|
|
16
|
-
if request.format.present? and request.format.html?
|
17
|
-
session["#{scope}_return_to"] = request.path if request.get?
|
18
|
-
# todo: doesn't seem to work
|
19
|
-
redirect_to send("new_#{scope}_two_factor_authentication_path")
|
20
|
-
else
|
21
|
-
render nothing: true, status: :unauthorized
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
7
|
end
|
26
8
|
|
27
9
|
end
|
data/lib/devise_castle/hooks.rb
CHANGED
@@ -8,7 +8,6 @@ end
|
|
8
8
|
Warden::Manager.before_logout do |record, warden, opts|
|
9
9
|
if record.respond_to?(:castle_id)
|
10
10
|
castle = warden.request.env['castle']
|
11
|
-
castle.logout
|
12
11
|
castle.track(user_id: record._castle_id, name: '$logout.succeeded')
|
13
12
|
end
|
14
13
|
end
|
@@ -35,26 +34,6 @@ end
|
|
35
34
|
Warden::Manager.after_set_user :except => :fetch do |record, warden, opts|
|
36
35
|
if record.respond_to?(:castle_id)
|
37
36
|
castle = warden.request.env['castle']
|
38
|
-
|
39
|
-
recommendation = castle.recommendation(user_id: record._castle_id)
|
40
|
-
|
41
|
-
if recommendation.action == 'ok'
|
42
|
-
castle.track(user_id: record._castle_id, name: '$login.succeeded')
|
43
|
-
castle.login(record._castle_id, email: record.email)
|
44
|
-
else
|
45
|
-
castle.track(user_id: record._castle_id, name: '$login.failed')
|
46
|
-
|
47
|
-
warden.logout(opts[:scope])
|
48
|
-
throw :warden, :scope => opts[:scope], :message => :signed_out
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Continous authentication
|
54
|
-
Warden::Manager.after_set_user do |record, warden, opts|
|
55
|
-
if record.respond_to?(:castle_id)
|
56
|
-
env = warden.request.env
|
57
|
-
castle = env['castle']
|
58
|
-
castle.authorize! unless env['castle.skip_authorization']
|
37
|
+
castle.track(user_id: record._castle_id, name: '$login.succeeded')
|
59
38
|
end
|
60
39
|
end
|
data/lib/devise_castle/model.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
def destroy_castle_user
|
12
12
|
castle_user_block do
|
13
|
-
::Castle::User.destroy_existing(
|
13
|
+
::Castle::User.destroy_existing(_castle_id)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -34,19 +34,6 @@
|
|
34
34
|
URI.encode(castle_id.to_s)
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
38
|
-
# Overwrites valid_for_authentication? from Devise::Models::Authenticatable
|
39
|
-
# for verifying whether a user is allowed to sign in or not.
|
40
|
-
def valid_for_authentication?
|
41
|
-
return super unless persisted?
|
42
|
-
|
43
|
-
if super
|
44
|
-
true
|
45
|
-
else
|
46
|
-
# TODO: track unsuccessful login
|
47
|
-
false
|
48
|
-
end
|
49
|
-
end
|
50
37
|
end
|
51
38
|
end
|
52
39
|
end
|
data/lib/devise_castle/routes.rb
CHANGED
@@ -3,7 +3,6 @@ module ActionDispatch::Routing
|
|
3
3
|
protected
|
4
4
|
|
5
5
|
def devise_castle(mapping, controllers)
|
6
|
-
resources :two_factor_authentication, :only => [:new, :show, :update, :edit], :path => mapping.path_names[:two_factor_authentication], :controller => controllers[:two_factor_authentication]
|
7
6
|
end
|
8
7
|
end
|
9
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_castle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Brissmyr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,27 +88,16 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- app/controllers/devise/devise_castle_controller.rb
|
91
|
-
- app/controllers/devise/two_factor_authentication_controller.rb
|
92
91
|
- app/controllers/devise_castle/sessions_controller.rb
|
93
|
-
- app/views/devise/two_factor_authentication/authenticator/edit.html.erb
|
94
|
-
- app/views/devise/two_factor_authentication/sms/edit.html.erb
|
95
|
-
- app/views/devise/two_factor_authentication/yubikey/edit.html.erb
|
96
92
|
- lib/devise_castle.rb
|
97
93
|
- lib/devise_castle/controllers/helpers.rb
|
98
94
|
- lib/devise_castle/hooks.rb
|
99
|
-
- lib/devise_castle/import.rb
|
100
95
|
- lib/devise_castle/mapping.rb
|
101
96
|
- lib/devise_castle/model.rb
|
102
97
|
- lib/devise_castle/railtie.rb
|
103
98
|
- lib/devise_castle/routes.rb
|
104
99
|
- lib/devise_castle/version.rb
|
105
|
-
- lib/generators/active_record/devise_castle_generator.rb
|
106
|
-
- lib/generators/active_record/templates/migration.rb
|
107
|
-
- lib/generators/devise_castle/devise_castle_generator.rb
|
108
|
-
- lib/generators/devise_castle/import_generator.rb
|
109
100
|
- lib/generators/devise_castle/install_generator.rb
|
110
|
-
- lib/generators/devise_castle/views_generator.rb
|
111
|
-
- lib/generators/mongoid/devise_castle_generator.rb
|
112
101
|
homepage: https://github.com/castle/devise_castle
|
113
102
|
licenses:
|
114
103
|
- MIT
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<h2><%= t "devise.two_factor_authentication.header" %></h2>
|
2
|
-
|
3
|
-
<p><%= t "devise.two_factor_authentication.edit.authenticator.instructions" %></p>
|
4
|
-
|
5
|
-
<%= form_tag([resource_name, :two_factor_authentication], :method => :put) do %>
|
6
|
-
<%= devise_error_messages! %>
|
7
|
-
<p><%= label_tag :code, t("devise.two_factor_authentication.edit.common.code_label") %><br />
|
8
|
-
<%= text_field_tag :code %></p>
|
9
|
-
<p><%= check_box_tag :trust_device %> <%= label_tag :trust_device %></p>
|
10
|
-
<%= hidden_field_tag(:challenge_id, @challenge.id) %>
|
11
|
-
<p><%= submit_tag t("devise.two_factor_authentication.edit.common.submit_button") %></p>
|
12
|
-
<% end -%>
|
13
|
-
|
14
|
-
<p><%= t "devise.two_factor_authentication.edit.common.recovery_message" %>
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<h2><%= t "devise.two_factor_authentication.header" %></h2>
|
2
|
-
|
3
|
-
<p>
|
4
|
-
<%= t "devise.two_factor_authentication.edit.sms.instructions" %>
|
5
|
-
<%= link_to t("devise.two_factor_authentication.edit.sms.resend"), send("new_#{resource_name}_two_factor_authentication_path") %>.
|
6
|
-
</p>
|
7
|
-
|
8
|
-
<%= form_tag([resource_name, :two_factor_authentication], :method => :put) do %>
|
9
|
-
<%= devise_error_messages! %>
|
10
|
-
<p><%= label_tag :code, t("devise.two_factor_authentication.edit.common.code_label") %><br />
|
11
|
-
<%= text_field_tag :code %></p>
|
12
|
-
<p><%= check_box_tag :trust_device %> <%= label_tag :trust_device %></p>
|
13
|
-
<%= hidden_field_tag(:challenge_id, @challenge.id) %>
|
14
|
-
<p><%= submit_tag t("devise.two_factor_authentication.edit.common.submit_button") %></p>
|
15
|
-
<% end -%>
|
16
|
-
|
17
|
-
<p><%= t "devise.two_factor_authentication.edit.common.recovery_message" %>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<h2><%= t "devise.two_factor_authentication.header" %></h2>
|
2
|
-
|
3
|
-
<p><%= t "devise.two_factor_authentication.edit.yubikey.instructions" %></p>
|
4
|
-
|
5
|
-
<%= form_tag([resource_name, :two_factor_authentication], :method => :put) do %>
|
6
|
-
<%= devise_error_messages! %>
|
7
|
-
<p><%= label_tag :code, t("devise.two_factor_authentication.edit.common.code_label") %><br />
|
8
|
-
<%= text_field_tag :code %></p>
|
9
|
-
<p><%= check_box_tag :trust_device %> <%= label_tag :trust_device %></p>
|
10
|
-
<%= hidden_field_tag(:challenge_id, @challenge.id) %>
|
11
|
-
<p><%= submit_tag t("devise.two_factor_authentication.edit.common.submit_button") %></p>
|
12
|
-
<% end -%>
|
13
|
-
|
14
|
-
<p><%= t "devise.two_factor_authentication.edit.common.recovery_message" %>
|
data/lib/devise_castle/import.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
module DeviseCastle
|
2
|
-
class ImportError < Exception; end
|
3
|
-
|
4
|
-
class Import
|
5
|
-
attr_reader :resource_class, :batch_size
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
begin
|
9
|
-
@resource_class = eval(options[:resource_class])
|
10
|
-
rescue NameError
|
11
|
-
raise ImportError, "No such class: #{options[:resource_class]}"
|
12
|
-
end
|
13
|
-
|
14
|
-
unless supported_orm?
|
15
|
-
raise ImportError, "Only ActiveRecord and Mongoid models are supported"
|
16
|
-
end
|
17
|
-
|
18
|
-
unless Castle.config.api_secret.present?
|
19
|
-
raise ImportError, "Please add an Castle API secret to your devise.rb"
|
20
|
-
end
|
21
|
-
|
22
|
-
@batch_size = [(options[:batch_size] || 100), 100].min
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.run(*args)
|
26
|
-
new(*args).run
|
27
|
-
end
|
28
|
-
|
29
|
-
def run
|
30
|
-
batches do |batch, resources|
|
31
|
-
begin
|
32
|
-
users = Castle::User.import(users: batch)
|
33
|
-
rescue Castle::Error => error
|
34
|
-
raise ImportError, error.message
|
35
|
-
end
|
36
|
-
|
37
|
-
users.zip(resources).each do |user, resource|
|
38
|
-
resource.castle_id = user.id
|
39
|
-
resource.save(validate: false)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def batches
|
45
|
-
if active_record?
|
46
|
-
resource_class.where("castle_id IS NULL").find_in_batches(:batch_size => batch_size) do |resources|
|
47
|
-
resources_for_wire = map_resources_to_castle_format(resources)
|
48
|
-
yield(resources_for_wire, resources) unless resources.count.zero?
|
49
|
-
end
|
50
|
-
elsif mongoid?
|
51
|
-
0.step(resource_class.where(:castle_id => nil).count, batch_size) do |offset|
|
52
|
-
resources_for_wire = map_resources_to_castle_format(resource_class.limit(batch_size).skip(offset))
|
53
|
-
yield(resources_for_wire, resources) unless resources.count.zero?
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def map_resources_to_castle_format(resources)
|
59
|
-
resources.map do |resource|
|
60
|
-
format = {}
|
61
|
-
format[:email] = resource.email unless resource.email.blank?
|
62
|
-
format[:id] = resource._castle_id
|
63
|
-
format[:created_at] = resource.created_at if resource.respond_to? :created_at
|
64
|
-
format
|
65
|
-
end.compact
|
66
|
-
end
|
67
|
-
|
68
|
-
def prepare_batch(batch)
|
69
|
-
{ :users => batch }.to_json
|
70
|
-
end
|
71
|
-
|
72
|
-
def active_record?
|
73
|
-
(defined?(ActiveRecord::Base) && (resource_class < ActiveRecord::Base))
|
74
|
-
end
|
75
|
-
|
76
|
-
def mongoid?
|
77
|
-
(defined?(Mongoid::Document) && (resource_class < Mongoid::Document))
|
78
|
-
end
|
79
|
-
|
80
|
-
def supported_orm?
|
81
|
-
active_record? || mongoid?
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rails/generators/active_record'
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module Generators
|
5
|
-
class DeviseCastleGenerator < ActiveRecord::Generators::Base
|
6
|
-
source_root File.expand_path("../templates", __FILE__)
|
7
|
-
|
8
|
-
def copy_devise_castle_migration
|
9
|
-
migration_template "migration.rb", "db/migrate/add_castle_to_#{table_name}.rb"
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class AddCastleTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
-
def up
|
3
|
-
change_table :<%= table_name %> do |t|
|
4
|
-
t.string :castle_id
|
5
|
-
end
|
6
|
-
|
7
|
-
add_index :<%= table_name %>, :castle_id, :unique => true
|
8
|
-
end
|
9
|
-
|
10
|
-
def down
|
11
|
-
remove_column :<%= table_name %>, :castle_id
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module DeviseCastle
|
2
|
-
module Generators
|
3
|
-
class DeviseCastleGenerator < Rails::Generators::NamedBase
|
4
|
-
namespace "devise_castle"
|
5
|
-
|
6
|
-
desc "Add :castle directive in the given model. Also generate migration for ActiveRecord"
|
7
|
-
|
8
|
-
def inject_devise_castle_content
|
9
|
-
path = File.join("app", "models", "#{file_path}.rb")
|
10
|
-
if File.exists?(path)
|
11
|
-
inject_into_file(path, "castle, :", :after => "devise :")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
hook_for :orm
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'generators/devise/views_generator'
|
2
|
-
|
3
|
-
module DeviseCastle
|
4
|
-
module Generators
|
5
|
-
class ViewsGenerator < Rails::Generators::Base
|
6
|
-
desc 'Copies all DeviseCastle views to your application.'
|
7
|
-
|
8
|
-
argument :scope, :required => false, :default => nil,
|
9
|
-
:desc => "The scope to copy views to"
|
10
|
-
|
11
|
-
include ::Devise::Generators::ViewPathTemplates
|
12
|
-
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
13
|
-
def copy_views
|
14
|
-
view_directory :two_factor_authentication
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|