active_model_otp 2.0.1 → 2.1.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
  SHA256:
3
- metadata.gz: 4f10c7c77b302adbd5a02bb37378c46eafd0d6aaf53f2f5ec7ac069bd888ab07
4
- data.tar.gz: 2572cac964589cc665f0a0dbaacaa7ca8fc226cef62ebeb122e591c487b6278d
3
+ metadata.gz: 973b2897bf7c434844a9ec652c599705fbfe6def2da99b20302059047ba960d1
4
+ data.tar.gz: 4ac0735f61e0d74109ec39d4a6b7504028a76d2ab74f31bde8e90dbd9625a61a
5
5
  SHA512:
6
- metadata.gz: e78abb140e71aca80842a896ef02abad3df97be46b57e096056b8480c150aa5c8c633725cb8d0aaa49eaf9e26b5846741ac9eb6b99a963f59a7b835e88101605
7
- data.tar.gz: 9d7d0fef52db81c831a728808b5768714fcbc64df126a65832a9ed86769379e4ee007f894193183a536ba2d1ea32343f77537fb732bd84de2168e75b02202bef
6
+ metadata.gz: 53612a20dc401b03c051c48450e7161388fed1ab5d2c7d43ebcf12dbec82ca8f12e05d033237f505257d79c4e3ba9861fe5bdae943280e0b625ebb9a0bb95e2d
7
+ data.tar.gz: 2cbb80548cccb92ff3ed398671c65aa600adc32de84a95b91287de67a4a7fbac45cf97d2d1d311bc1fc141cdb630a1a4e803a3785e79449ec00fea8ce3db5f2c
@@ -9,13 +9,13 @@ gemfile:
9
9
  - gemfiles/rails_5.0.gemfile
10
10
  - gemfiles/rails_5.1.gemfile
11
11
  - gemfiles/rails_5.2.gemfile
12
- - gemfiles/rails_6.0.0.rc1.gemfile
12
+ - gemfiles/rails_6.0.gemfile
13
13
  matrix:
14
14
  exclude:
15
15
  - rvm: 2.3
16
- gemfile: gemfiles/rails_6.0.0.rc1.gemfile
16
+ gemfile: gemfiles/rails_6.0.gemfile
17
17
  - rvm: 2.4
18
- gemfile: gemfiles/rails_6.0.0.rc1.gemfile
18
+ gemfile: gemfiles/rails_6.0.gemfile
19
19
  fast_finish: true
20
20
  allow_failures:
21
21
  - rvm: ruby-head
data/Appraisals CHANGED
@@ -17,9 +17,9 @@ appraise "rails-5.2" do
17
17
  gem "activemodel-serializers-xml"
18
18
  end
19
19
 
20
- appraise "rails-6.0.0.rc1" do
21
- gem "activerecord", "6.0.0.rc1"
22
- gem "activemodel", "6.0.0.rc1"
20
+ appraise "rails-6.0" do
21
+ gem "activerecord", "~> 6.0"
22
+ gem "activemodel", "~> 6.0"
23
23
  gem "activemodel-serializers-xml"
24
24
  gem "sqlite3", "~> 1.4"
25
25
  end
@@ -1,17 +1 @@
1
- # v1.2.0
2
- - Added Counter based OTP (HOTP) (@ResultsMayVary ) https://github.com/heapsource/active_model_otp/pull/19
3
- - Adding options to provisioning uri, so we can include issuer (@doon) https://github.com/heapsource/active_model_otp/pull/15
4
-
5
- # v1.1.0
6
- - Add function to re-geterante the OTP secret (@TikiTDO) https://github.com/heapsource/active_model_otp/pull/14
7
- - Added option to pass OTP length (@shivanibhanwal) https://github.com/heapsource/active_model_otp/pull/13
8
-
9
- # v1.0.0
10
- - Avoid overriding predefined otp_column value when initializing resource (Ilan Stern) https://github.com/heapsource/active_model_otp/pull/10
11
- - Pad OTP codes with less than 6 digits (Johan Brissmyr) https://github.com/heapsource/active_model_otp/pull/7
12
- - Get rid of deprecation warnings in Rails 4.1 (Nick DeMonner)
13
-
14
- # v0.1.0
15
- - OTP codes can be in 5 or 6 digits (André Luis Leal Cardoso Junior)
16
- - Require 'cgi', rotp needs it for encoding parameters (André Luis Leal Cardoso Junior)
17
- - Change column name for otp secret key (robertomiranda)
1
+ CHANGELOG it's been deprecated in favor of https://github.com/heapsource/active_model_otp/releases
data/README.md CHANGED
@@ -5,11 +5,12 @@
5
5
 
6
6
  # ActiveModel::Otp
7
7
 
8
- **ActiveModel::Otp** makes adding **Two Factor Authentication** (TFA) to a model simple. Let's see what's required to get AMo::Otp working in our Application, using Rails 5.0 (AMo::Otp is also compatible with Rails 4.x versions). We're going to use a User model and try to add options provided by **ActiveMOdel::Otp**. Inspired by AM::SecurePassword
8
+ **ActiveModel::Otp** makes adding **Two Factor Authentication** (TFA) to a model simple. Let's see what's required to get AMo::Otp working in our Application, using Rails 5.0 (AMo::Otp is also compatible with Rails 4.x versions). We're going to use a User model and try to add options provided by **ActiveModel::Otp**. Inspired by AM::SecurePassword
9
9
 
10
10
  ## Dependencies
11
11
 
12
12
  * [ROTP](https://github.com/mdp/rotp) 5.0 or higher
13
+ * Ruby 2.3 or greater
13
14
 
14
15
  ## Installation
15
16
 
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 2.3"
20
22
 
21
23
  spec.add_dependency "activemodel"
22
24
  spec.add_dependency "rotp", "~> 5.0.0"
@@ -2,8 +2,8 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "6.0.0.rc1"
6
- gem "activemodel", "6.0.0.rc1"
5
+ gem "activerecord", "~> 6.0"
6
+ gem "activemodel", "~> 6.0"
7
7
  gem "activemodel-serializers-xml"
8
8
  gem "sqlite3", "~> 1.4"
9
9
 
@@ -15,7 +15,7 @@ module ActiveModel
15
15
 
16
16
  include InstanceMethodsOnActivation
17
17
 
18
- before_create do
18
+ before_create(options.slice(:if, :unless)) do
19
19
  self.otp_regenerate_secret if !otp_column
20
20
  self.otp_regenerate_counter if otp_counter_based && !otp_counter
21
21
  end
@@ -49,7 +49,7 @@ module ActiveModel
49
49
  result = hotp.verify(code, otp_counter)
50
50
  if result && options[:auto_increment]
51
51
  self.otp_counter += 1
52
- save if respond_to?(:new_record) && !new_record?
52
+ save if respond_to?(:changed?) && !new_record?
53
53
  end
54
54
  result
55
55
  else
@@ -66,7 +66,7 @@ module ActiveModel
66
66
  if otp_counter_based
67
67
  if options[:auto_increment]
68
68
  self.otp_counter += 1
69
- save if respond_to?(:new_record) && !new_record?
69
+ save if respond_to?(:changed?) && !new_record?
70
70
  end
71
71
  ROTP::HOTP.new(otp_column, digits: otp_digits).at(self.otp_counter)
72
72
  else
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  module Otp
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OptInTwoFactor
4
+ extend ActiveModel::Callbacks
5
+ include ActiveModel::Validations
6
+ include ActiveModel::OneTimePassword
7
+
8
+ define_model_callbacks :create
9
+ attr_accessor :otp_secret_key, :email
10
+
11
+ has_one_time_password unless: :otp_opt_in?
12
+
13
+ def otp_opt_in?
14
+ true
15
+ end
16
+ end
@@ -17,6 +17,10 @@ class OtpTest < MiniTest::Unit::TestCase
17
17
  @ar_user = ActiverecordUser.new
18
18
  @ar_user.email = 'roberto@heapsource.com'
19
19
  @ar_user.run_callbacks :create
20
+
21
+ @opt_in = OptInTwoFactor.new
22
+ @opt_in.email = 'roberto@heapsource.com'
23
+ @opt_in.run_callbacks :create
20
24
  end
21
25
 
22
26
  def test_authenticate_with_otp
@@ -49,6 +53,14 @@ class OtpTest < MiniTest::Unit::TestCase
49
53
  assert code != @ar_user.otp_code(auto_increment: true)
50
54
  end
51
55
 
56
+ def test_opt_in_two_factor
57
+ assert @opt_in.otp_column.nil?
58
+
59
+ @opt_in.otp_regenerate_secret
60
+ code = @opt_in.otp_code
61
+ assert @opt_in.authenticate_otp(code)
62
+ end
63
+
52
64
  def test_authenticate_with_otp_when_drift_is_allowed
53
65
  code = @user.otp_code(Time.now - 30)
54
66
  assert @user.authenticate_otp(code, drift: 60)
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_otp
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Iguaran
8
8
  - Roberto Miranda
9
9
  - Heapsource
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-06-07 00:00:00.000000000 Z
13
+ date: 2020-12-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -133,12 +133,13 @@ files:
133
133
  - gemfiles/rails_5.0.gemfile
134
134
  - gemfiles/rails_5.1.gemfile
135
135
  - gemfiles/rails_5.2.gemfile
136
- - gemfiles/rails_6.0.0.rc1.gemfile
136
+ - gemfiles/rails_6.0.gemfile
137
137
  - lib/active_model/one_time_password.rb
138
138
  - lib/active_model/otp/version.rb
139
139
  - lib/active_model_otp.rb
140
140
  - test/models/activerecord_user.rb
141
141
  - test/models/member.rb
142
+ - test/models/opt_in_two_factor.rb
142
143
  - test/models/user.rb
143
144
  - test/models/visitor.rb
144
145
  - test/one_time_password_test.rb
@@ -148,7 +149,7 @@ homepage: ''
148
149
  licenses:
149
150
  - MIT
150
151
  metadata: {}
151
- post_install_message:
152
+ post_install_message:
152
153
  rdoc_options: []
153
154
  require_paths:
154
155
  - lib
@@ -156,20 +157,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
157
  requirements:
157
158
  - - ">="
158
159
  - !ruby/object:Gem::Version
159
- version: '0'
160
+ version: '2.3'
160
161
  required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  requirements:
162
163
  - - ">="
163
164
  - !ruby/object:Gem::Version
164
165
  version: '0'
165
166
  requirements: []
166
- rubygems_version: 3.0.1
167
- signing_key:
167
+ rubygems_version: 3.0.3
168
+ signing_key:
168
169
  specification_version: 4
169
170
  summary: Adds methods to set and authenticate against one time passwords.
170
171
  test_files:
171
172
  - test/models/activerecord_user.rb
172
173
  - test/models/member.rb
174
+ - test/models/opt_in_two_factor.rb
173
175
  - test/models/user.rb
174
176
  - test/models/visitor.rb
175
177
  - test/one_time_password_test.rb