trestle-auth-otp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/config/initializers/trestle.rb +18 -0
- data/lib/trestle/auth/otp.rb +1 -0
- data/lib/trestle/auth/otp/version.rb +1 -1
- data/trestle-auth-otp.gemspec +3 -0
- metadata +29 -2
- data/app/controllers/trestle/auth/sessions_controller.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab6852c8a3f306278dcb768a3402db8e9c5c60b326591738f048c0171872b8ed
|
4
|
+
data.tar.gz: 78b38ba718aa93cea3475987b2df9e1fbe0323150e437a53d77d94e46eb5b59f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6bcfddae92e9878c7697044b4d7e432663cba9ca0bacfde9b3c5cb9f6435fcd5ae5da4c9671894cdb8f8c925573b72d17d206f6729fa92297caa83fe8ef6db
|
7
|
+
data.tar.gz: c64a1b2b991cbad6a55c86e908e477b47f76f66c6eddac04e9b15b91ae22e1a1f80e3539f0a08b67dace50518da57ad1156c80ec7e3c721023047dea6a115c0b
|
data/.gitignore
CHANGED
@@ -4,4 +4,22 @@ Trestle.configure do |config|
|
|
4
4
|
render 'trestle/auth/otp'
|
5
5
|
end
|
6
6
|
|
7
|
+
config.auth.authenticate = ->(params) {
|
8
|
+
|
9
|
+
scope = Trestle.config.auth.user_scope
|
10
|
+
|
11
|
+
user = scope.authenticate(params[Trestle.config.auth.authenticate_with], params[:password])
|
12
|
+
|
13
|
+
if user && user.otp_module?
|
14
|
+
if params[:otp_code_token].present? && user.authenticate_otp(params[:otp_code_token], drift: 60)
|
15
|
+
return user
|
16
|
+
else
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
else
|
20
|
+
return user
|
21
|
+
end
|
22
|
+
|
23
|
+
}
|
24
|
+
|
7
25
|
end
|
data/lib/trestle/auth/otp.rb
CHANGED
data/trestle-auth-otp.gemspec
CHANGED
@@ -26,4 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "rqrcode", "~> 1.1"
|
27
27
|
|
28
28
|
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
29
|
+
spec.add_development_dependency "show_me_the_cookies", "~> 5.0"
|
30
|
+
spec.add_development_dependency "timecop", "~> 0.9.1"
|
31
|
+
|
29
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trestle-auth-otp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emanuele Barban
|
@@ -80,6 +80,34 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: show_me_the_cookies
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: timecop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.1
|
83
111
|
description:
|
84
112
|
email:
|
85
113
|
executables: []
|
@@ -94,7 +122,6 @@ files:
|
|
94
122
|
- LICENSE
|
95
123
|
- README.md
|
96
124
|
- Rakefile
|
97
|
-
- app/controllers/trestle/auth/sessions_controller.rb
|
98
125
|
- app/views/trestle/admin/_qr_code.html.erb
|
99
126
|
- app/views/trestle/auth/_otp.html.erb
|
100
127
|
- bin/rails
|
@@ -1,48 +0,0 @@
|
|
1
|
-
class Trestle::Auth::SessionsController < Trestle::ApplicationController
|
2
|
-
layout 'trestle/auth'
|
3
|
-
|
4
|
-
skip_before_action :authenticate_user, only: [:new, :create]
|
5
|
-
skip_before_action :require_authenticated_user
|
6
|
-
|
7
|
-
def new; end
|
8
|
-
|
9
|
-
def create
|
10
|
-
if user = Trestle.config.auth.authenticate(params)
|
11
|
-
|
12
|
-
if user&.otp_module?
|
13
|
-
if params[:otp_code_token].size > 0
|
14
|
-
if user.authenticate_otp(params[:otp_code_token], drift: 60)
|
15
|
-
continue_sign_in(user)
|
16
|
-
else
|
17
|
-
logout!
|
18
|
-
flash[:error] = t('admin.auth.error', default: 'Bad Credentials Supplied.')
|
19
|
-
redirect_to instance_exec(&Trestle.config.auth.redirect_on_login)
|
20
|
-
end
|
21
|
-
else
|
22
|
-
logout!
|
23
|
-
flash[:error] = t('admin.auth.error', default: 'Your account needs to supply a token.')
|
24
|
-
redirect_to instance_exec(&Trestle.config.auth.redirect_on_login)
|
25
|
-
end
|
26
|
-
else
|
27
|
-
continue_sign_in(user)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
flash[:error] = t('admin.auth.error', default: 'Incorrect login details.')
|
31
|
-
redirect_to action: :new
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def destroy
|
36
|
-
logout!
|
37
|
-
redirect_to instance_exec(&Trestle.config.auth.redirect_on_logout)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def continue_sign_in(user)
|
43
|
-
login!(user)
|
44
|
-
remember_me! if params[:remember_me] == '1'
|
45
|
-
redirect_to previous_location || instance_exec(&Trestle.config.auth.redirect_on_login)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|