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

use the remembered device when switching #15042

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,26 @@ def successful_2fa_transmission(service, transmit)
##
# 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

##
# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ def self.device_type
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
Expand Down
Loading