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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.rbindex 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 verificationdef 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::RecordNotFoundrender_404falseend+ 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 resenddef service_from_resend_paramsdiff --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.rbindex 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 TwoFactorAuthenticationdef 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))enddef options_for_get(relying_party)@options_for_get ||= relying_party.options_for_authentication(- user_verification: "discouraged", # we do not require user verificationallow: [webauthn_external_id] # TODO: Maybe also allow all other tokens? Let's see)end