Skip to content
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

Merged
merged 23 commits into from
Jun 21, 2021

Conversation

pedrofurtado
Copy link
Collaborator

@robertomiranda You review on it will be awesome 🤝

@@ -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)

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)

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

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

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

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.

2.times { assert_match(otp_code, @interval_user.otp_code) }
sleep 5
refute_match(otp_code, @interval_user.otp_code)

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

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

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,

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,

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,

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.

Copy link
Member

@robertomiranda robertomiranda left a 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 🙇

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
lib/active_model/one_time_password.rb Outdated Show resolved Hide resolved
Comment on lines 13 to 17
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
Copy link
Member

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

Copy link
Collaborator Author

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

pedrofurtado and others added 4 commits June 21, 2021 08:40
Co-authored-by: Roberto Miranda <rjmaltamar@gmail.com>
Co-authored-by: Roberto Miranda <rjmaltamar@gmail.com>
Co-authored-by: Roberto Miranda <rjmaltamar@gmail.com>
@pedrofurtado
Copy link
Collaborator Author

@robertomiranda Suggestions applied! Let me know your thoughts about the changes 👍

@robertomiranda
Copy link
Member

Nice one @pedrofurtado! 👏

@pedrofurtado pedrofurtado merged commit 8bf4150 into heapsource:main Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants