-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interval feature for TOTP #88
Conversation
@@ -166,7 +167,7 @@ def totp_code(options = {}) | |||
else | |||
options | |||
end | |||
ROTP::TOTP.new(otp_column, digits: otp_digits).at(time) | |||
ROTP::TOTP.new(otp_column, digits: otp_digits, interval: otp_interval).at(time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [87/80]
@@ -144,7 +145,7 @@ def authenticate_hotp(code, options = {}) | |||
end | |||
|
|||
def authenticate_totp(code, options = {}) | |||
totp = ROTP::TOTP.new(otp_column, digits: otp_digits) | |||
totp = ROTP::TOTP.new(otp_column, digits: otp_digits, interval: otp_interval) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [85/80]
@@ -7,13 +7,14 @@ def has_one_time_password(options = {}) | |||
cattr_accessor :otp_column_name, :otp_counter_column_name, | |||
:otp_backup_codes_column_name | |||
class_attribute :otp_digits, :otp_counter_based, | |||
:otp_backup_codes_count, :otp_one_time_backup_codes | |||
:otp_backup_codes_count, :otp_one_time_backup_codes, :otp_interval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [90/80]
@@ -0,0 +1,3 @@ | |||
class DefaultIntervalUser < ActiveRecord::Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
@@ -0,0 +1,3 @@ | |||
class IntervalUser < ActiveRecord::Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
test/one_time_password_test.rb
Outdated
2.times { assert_match(otp_code, @interval_user.otp_code) } | ||
sleep 5 | ||
refute_match(otp_code, @interval_user.otp_code) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
test/schema.rb
Outdated
t.string :otp_secret_key | ||
t.timestamps | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
test/schema.rb
Outdated
@@ -8,4 +8,20 @@ | |||
t.string :otp_secret_key | |||
t.timestamps | |||
end | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
totp = ROTP::TOTP.new(otp_column, digits: otp_digits) | ||
totp = ROTP::TOTP.new( | ||
otp_column, | ||
digits: otp_digits, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
@@ -144,7 +146,11 @@ def authenticate_hotp(code, options = {}) | |||
end | |||
|
|||
def authenticate_totp(code, options = {}) | |||
totp = ROTP::TOTP.new(otp_column, digits: otp_digits) | |||
totp = ROTP::TOTP.new( | |||
otp_column, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
@@ -7,13 +7,15 @@ def has_one_time_password(options = {}) | |||
cattr_accessor :otp_column_name, :otp_counter_column_name, | |||
:otp_backup_codes_column_name | |||
class_attribute :otp_digits, :otp_counter_based, | |||
:otp_backup_codes_count, :otp_one_time_backup_codes | |||
:otp_backup_codes_count, :otp_one_time_backup_codes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/TrailingWhitespace: Trailing whitespace detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @pedrofurtado just minor suggestions around the notes in the README file and a nitpick around how we handle the default values that would be good to address before merging this PR 👍
Thank you 🙇
self.otp_column_name = (options[:column_name] || "otp_secret_key").to_s | ||
self.otp_digits = options[:length] || 6 | ||
|
||
self.otp_counter_based = (options[:counter_based] || false) | ||
self.otp_counter_column_name = (options[:counter_column_name] || "otp_counter").to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this PR but would be good to start to move the default values to class constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created another PR for this suggestion 🎉 #89
Co-authored-by: Roberto Miranda <rjmaltamar@gmail.com>
Co-authored-by: Roberto Miranda <rjmaltamar@gmail.com>
Co-authored-by: Roberto Miranda <rjmaltamar@gmail.com>
@robertomiranda Suggestions applied! Let me know your thoughts about the changes 👍 |
Nice one @pedrofurtado! 👏 |
@robertomiranda You review on it will be awesome 🤝