google-authenticator-rails 1.5.1 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ae116066dcdcca361997f0f22706e59454f8b4b
4
- data.tar.gz: 6fb7e9435cdd2e8e69cd90e294fde9c0780587b5
3
+ metadata.gz: 19391728ca506273484c8691492ba1a09b2024ae
4
+ data.tar.gz: 57e4b1ce9b77074db2be9212b73a6a8f6f43ee02
5
5
  SHA512:
6
- metadata.gz: 0aeaee230b02e18fdcc3d7eddd7e891329d5420af79b0be27d6ad1b6e1c844586e492b66997b86482d6a5c82a2d542e163e484f3eae31e797542e92a0b289ab7
7
- data.tar.gz: db86ad2e95458da74abffd87f401a5406793146dc4354536e53f8db111b01fc57379ba65a6cf8430c50b968c2c57e3289f4d874482dbd0036a40f3297661e305
6
+ metadata.gz: e87812aca056ca5be5474fd3384bc7851104254db7b325949988e16fa3ac12546b6581f8394d301a8b3f800a6a305404dcb766f16d609756a285ee3806ed7b04
7
+ data.tar.gz: d13dd058fb08ab3dba40d126daabaaf2e52ad0c8c59124f099cab59dac30437268f01b3315443c5bf0b8a294d3c3b0bb01a99eecd0910a1c7a1a3f4ce9114e8a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google-authenticator-rails (1.5.1)
4
+ google-authenticator-rails (1.6.0)
5
5
  actionpack
6
6
  activerecord
7
7
  google-qr
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:
@@ -72,7 +72,8 @@ module GoogleAuthenticatorRails # :nodoc:
72
72
  end
73
73
 
74
74
  def google_issuer
75
- self.class.google_issuer
75
+ issuer = self.class.google_issuer
76
+ issuer.is_a?(Proc) ? issuer.call(self) : issuer
76
77
  end
77
78
 
78
79
  def google_secret_encryptor
@@ -1,3 +1,3 @@
1
1
  module GoogleAuthenticatorRails
2
- VERSION = "1.5.1"
2
+ VERSION = "1.6.0"
3
3
  end
@@ -237,9 +237,14 @@ describe GoogleAuthenticatorRails do
237
237
  end
238
238
 
239
239
  context 'custom proc' do
240
- let(:user) { UserFactory.create ProcUser }
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 ProcUser < BaseUser
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.5.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-10 00:00:00.000000000 Z
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