Skip to content

Commit

Permalink
Add drift period
Browse files Browse the repository at this point in the history
  • Loading branch information
raccube committed Oct 23, 2020
1 parent ee4b7e2 commit d20f527
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/user/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create
warden.lock!
render 'auth/two_factor_authentication'
else
if resource.authenticate_otp(params[:user][:otp_attempt])
if resource.authenticate_otp(params[:user][:otp_attempt], drift: APP_CONFIG.fetch(:otp_drift_period, 30).to_i)
continue_sign_in(resource, resource_name)
else
sign_out(resource)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def update_2fa
req_params = params.require(:user).permit(:otp_validation)
current_user.otp_module = :enabled

if current_user.authenticate_otp(req_params[:otp_validation])
if current_user.authenticate_otp(req_params[:otp_validation], drift: APP_CONFIG.fetch(:otp_drift_period, 30).to_i)
flash[:success] = t('views.auth.2fa.setup.success')
current_user.save!
else
Expand Down
3 changes: 3 additions & 0 deletions config/justask.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ hcaptcha:
enabled: false
site_key: ''
secret_key: ''

# TOTP Drift period in seconds
otp_drift_period: 30

0 comments on commit d20f527

Please sign in to comment.