Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

use the remembered device when switching (#15042)

Oliver Güntherf66825d45824
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
index bb770fbe1ea..a16a2a07060 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
@@ -84,7 +84,7 @@ module ::TwoFactorAuthentication
##
# Create a token service for the current user
# with an optional override to use a non-default channel
- def otp_service(user, use_channel: nil, use_device: nil)
+ def otp_service(user, use_channel: nil, use_device: remembered_device(user))
session[:two_factor_authentication_device_id] = use_device.try(:id)
::TwoFactorAuthentication::TokenService.new user:, use_channel:, use_device:
end
@@ -92,16 +92,18 @@ module ::TwoFactorAuthentication
##
# Get the used device for verification
def otp_service_for_verification(user)
- use_device =
- if session[:two_factor_authentication_device_id]
- user.otp_devices.find(session[:two_factor_authentication_device_id])
- end
- otp_service(user, use_device:)
+ otp_service(user, use_device: remembered_device(user))
rescue ActiveRecord::RecordNotFound
render_404
false
end
+ def remembered_device(user)
+ if session[:two_factor_authentication_device_id]
+ user.otp_devices.find(session[:two_factor_authentication_device_id])
+ end
+ end
+
##
# Detect overridden channel or device from params when trying to resend
def service_from_resend_params
diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb
index c4aefe990b4..d36848dbac0 100644
--- a/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb
+++ b/modules/two_factor_authentication/app/models/two_factor_authentication/device/webauthn.rb
@@ -21,14 +21,12 @@ module TwoFactorAuthentication
def options_for_create(relying_party)
@options_for_create ||= relying_party.options_for_registration(
user: { id: user.webauthn_id, name: user.name },
- exclude: TwoFactorAuthentication::Device::Webauthn.where(user:).pluck(:webauthn_external_id),
- authenticator_selection: { user_verification: "discouraged" }
+ exclude: TwoFactorAuthentication::Device::Webauthn.where(user:).pluck(:webauthn_external_id)
)
end
def options_for_get(relying_party)
@options_for_get ||= relying_party.options_for_authentication(
- user_verification: "discouraged", # we do not require user verification
allow: [webauthn_external_id] # TODO: Maybe also allow all other tokens? Let's see
)
end