google-authenticator-rails 1.5.1 → 1.6.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -0
- data/lib/google-authenticator-rails/active_record/helpers.rb +2 -1
- data/lib/google-authenticator-rails/version.rb +1 -1
- data/spec/google_authenticator_spec.rb +6 -1
- data/spec/spec_helper.rb +8 -1
- metadata +2 -3
- data/lib/tasks/google_authenticator.rake +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19391728ca506273484c8691492ba1a09b2024ae
|
4
|
+
data.tar.gz: 57e4b1ce9b77074db2be9212b73a6a8f6f43ee02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e87812aca056ca5be5474fd3384bc7851104254db7b325949988e16fa3ac12546b6581f8394d301a8b3f800a6a305404dcb766f16d609756a285ee3806ed7b04
|
7
|
+
data.tar.gz: d13dd058fb08ab3dba40d126daabaaf2e52ad0c8c59124f099cab59dac30437268f01b3315443c5bf0b8a294d3c3b0bb01a99eecd0910a1c7a1a3f4ce9114e8a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -222,6 +222,14 @@ class User
|
|
222
222
|
end
|
223
223
|
```
|
224
224
|
|
225
|
+
You can also use a Proc to set a dynamic issuer for multi-tenant applications or any other custom needs:
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
class User
|
229
|
+
acts_as_google_authenticated :issuer => Proc.new { |user| user.admin? ? "Example Admin" : "example.com" }
|
230
|
+
end
|
231
|
+
```
|
232
|
+
|
225
233
|
This way your user will have the name of your site at the authenticator card besides the current token.
|
226
234
|
|
227
235
|
Here's what the issuers look like in Google Authenticator for iPhone:
|
@@ -237,9 +237,14 @@ describe GoogleAuthenticatorRails do
|
|
237
237
|
end
|
238
238
|
|
239
239
|
context 'custom proc' do
|
240
|
-
let(:user) { UserFactory.create
|
240
|
+
let(:user) { UserFactory.create ProcLabelUser }
|
241
241
|
it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest_user%40futureadvisor-admin%3Fsecret%3D#{secret}&chs=200x200" }
|
242
242
|
end
|
243
|
+
|
244
|
+
context 'custom issuer' do
|
245
|
+
let(:user) { UserFactory.create ProcIssuerUser }
|
246
|
+
it { should eq "https://chart.googleapis.com/chart?cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%40example.com%3Fissuer%3DFA%2BAdmin%26secret%3D#{secret}&chs=200x200" }
|
247
|
+
end
|
243
248
|
|
244
249
|
context 'method defined by symbol' do
|
245
250
|
let(:user) { UserFactory.create SymbolUser }
|
data/spec/spec_helper.rb
CHANGED
@@ -117,10 +117,17 @@ class DriftUser < BaseUser
|
|
117
117
|
acts_as_google_authenticated :drift => 31
|
118
118
|
end
|
119
119
|
|
120
|
-
class
|
120
|
+
class ProcLabelUser < BaseUser
|
121
121
|
acts_as_google_authenticated :method => Proc.new { |user| "#{user.user_name}@futureadvisor-admin" }
|
122
122
|
end
|
123
123
|
|
124
|
+
class ProcIssuerUser < BaseUser
|
125
|
+
acts_as_google_authenticated :issuer => Proc.new { |user| user.admin? ? "FA Admin" : "FutureAdvisor" }
|
126
|
+
def admin?
|
127
|
+
true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
124
131
|
class SymbolUser < BaseUser
|
125
132
|
acts_as_google_authenticated :method => :email
|
126
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-authenticator-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared McFarland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rotp
|
@@ -177,7 +177,6 @@ files:
|
|
177
177
|
- lib/google-authenticator-rails/session/base.rb
|
178
178
|
- lib/google-authenticator-rails/session/persistence.rb
|
179
179
|
- lib/google-authenticator-rails/version.rb
|
180
|
-
- lib/tasks/google_authenticator.rake
|
181
180
|
- spec/action_controller/integration_spec.rb
|
182
181
|
- spec/action_controller/rails_adapter_spec.rb
|
183
182
|
- spec/google_authenticator_spec.rb
|
@@ -1,55 +0,0 @@
|
|
1
|
-
namespace :google_authenticator do
|
2
|
-
|
3
|
-
def do_encrypt(args, already_encrypted, op_name)
|
4
|
-
model_names = if args[:optional_model_list]
|
5
|
-
args.extras.unshift(args[:optional_model_list])
|
6
|
-
else
|
7
|
-
# Adapted from https://stackoverflow.com/a/8248849/7478194
|
8
|
-
Dir[Rails.root.join('app/models/*.rb').to_s].map { |filename| File.basename(filename, '.rb').camelize }
|
9
|
-
end
|
10
|
-
|
11
|
-
ActiveRecord::Base.transaction do
|
12
|
-
match_op = " = #{already_encrypted ? 138 : 16}"
|
13
|
-
model_names.each do |model_name|
|
14
|
-
klass = model_name.constantize
|
15
|
-
next unless klass.ancestors.include?(ActiveRecord::Base) && klass.try(:google_secrets_encrypted)
|
16
|
-
print "#{op_name}ing model #{klass.name.inspect} (table #{klass.table_name.inspect}): "
|
17
|
-
count = 0
|
18
|
-
klass.where("LENGTH(#{klass.google_secret_column})#{match_op}").find_each do |record|
|
19
|
-
yield record
|
20
|
-
count += 1
|
21
|
-
end
|
22
|
-
puts "#{count} #{'secret'.pluralize(count)} #{op_name}ed"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'Encrypt all secret columns (add the :encrypt_secrets options *before* running)'
|
28
|
-
task :encrypt_secrets, [:optional_model_list] => :environment do |_t, args|
|
29
|
-
do_encrypt(args, false, 'Encrypt') { |record| record.encrypt_google_secret! }
|
30
|
-
end
|
31
|
-
|
32
|
-
desc 'Re-encrypt all secret columns from old_secret_key_base to secret_key_base'
|
33
|
-
task :reencrypt_secrets, [:optional_model_list] => :environment do |_t, args|
|
34
|
-
if Rails.application.secrets.old_secret_key_base.blank?
|
35
|
-
puts 'old_secret_key_base is not set in config/secrets.yml'
|
36
|
-
else
|
37
|
-
secret_encryptor = GoogleAuthenticatorRails::ActiveRecord::Helpers.get_google_secret_encryptor
|
38
|
-
Rails.application.secrets[:secret_key_base] = Rails.application.secrets.old_secret_key_base
|
39
|
-
Rails.application.instance_eval { @caching_key_generator = nil }
|
40
|
-
old_secret_encryptor = GoogleAuthenticatorRails::ActiveRecord::Helpers.get_google_secret_encryptor
|
41
|
-
do_encrypt(args, true, 'Re-encrypt') do |record|
|
42
|
-
GoogleAuthenticatorRails.secret_encryptor = old_secret_encryptor
|
43
|
-
plain_secret = record.google_secret_value
|
44
|
-
GoogleAuthenticatorRails.secret_encryptor = secret_encryptor
|
45
|
-
record.send(:change_google_secret_to!, plain_secret)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
desc 'Decrypt all secret columns (remove the :encrypt_secrets options *after* running)'
|
51
|
-
task :decrypt_secrets, [:optional_model_list] => :environment do |_t, args|
|
52
|
-
do_encrypt(args, true, 'Decrypt') { |record| record.send(:change_google_secret_to!, record.google_secret_value, false) }
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|