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

Implement authentication with WebAuthn device on login

Klaus Zandersf20fc3d3145c
diff --git a/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts b/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts
index 480f37abcb4..6d201ba281a 100644
--- a/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts
@@ -28,21 +28,55 @@
* ++
*/
-import { Controller } from "@hotwired/stimulus";
-import * as WebAuthnJSON from "@github/webauthn-json/browser-ponyfill";
-import QrCreator from "qr-creator";
+import { Controller } from '@hotwired/stimulus';
+import * as WebAuthnJSON from '@github/webauthn-json/browser-ponyfill';
+import QrCreator from 'qr-creator';
export default class TwoFactorAuthenticationController extends Controller {
- static targets = ["resendOptions", "qrCodeElement", "webauthnCredential"];
+ static targets = ['resendOptions', 'qrCodeElement', 'webauthnCredential'];
declare readonly resendOptionsTarget: HTMLElement;
declare readonly webauthnCredentialTarget: HTMLInputElement;
- async onCreateDevice(event: Event) {
- const data = (event.target as HTMLElement).dataset;
+ async onVerifyDevice(event: SubmitEvent) {
+ const form = event.target as HTMLFormElement;
+ const data = form.dataset;
+
+ // We are not in the context of verifying a WebAuthn device, so we can just submit the form
+ if (data.deviceType !== 'webauthn') {
+ return true;
+ }
+
+ event.preventDefault();
+
+ try {
+ const verifyOptionsRequest = await fetch(data.challengeUrl as string);
+ const verifyOptions = await verifyOptionsRequest.text();
+
+ const options = WebAuthnJSON.parseRequestOptionsFromJSON({
+ publicKey: JSON.parse(verifyOptions),
+ });
+
+ const credential = await WebAuthnJSON.get(options);
+
+ if (credential) {
+ this.webauthnCredentialTarget.value = JSON.stringify(credential);
+ form.submit();
+ }
+
+ return true;
+ } catch (error) {
+ console.log(`Error registering device: ${error}`);
+ return false;
+ }
+ }
+
+ async onCreateDevice(event: SubmitEvent) {
+ const form = event.target as HTMLFormElement;
+ const data = form.dataset;
// We are not in the context of adding a WebAuthn device, so we can just submit the form
- if (data.deviceType !== "webauthn") {
+ if (data.deviceType !== 'webauthn') {
return true;
}
@@ -60,7 +94,6 @@ export default class TwoFactorAuthenticationController extends Controller {
if (credential) {
this.webauthnCredentialTarget.value = JSON.stringify(credential);
- const form = event.target as HTMLFormElement;
form.submit();
}
@@ -76,12 +109,12 @@ export default class TwoFactorAuthenticationController extends Controller {
{
text: target.dataset.value as string,
radius: 0,
- ecLevel: "H",
- fill: "#222222",
- background: "#FFFFFF",
+ ecLevel: 'H',
+ fill: '#222222',
+ background: '#FFFFFF',
size: 250,
},
- target
+ target,
);
}
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 80377ed5506..7a33d80c34b 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
@@ -15,7 +15,7 @@ module ::TwoFactorAuthentication
# Require authenticated user from the core to be present
before_action :require_authenticated_user,
- only: %i(request_otp enter_backup_code verify_backup_code confirm_otp retry)
+ only: %i(request_otp enter_backup_code verify_backup_code confirm_otp retry webauthn_challenge)
before_action :ensure_valid_configuration, only: [:request_otp]
@@ -41,7 +41,11 @@ module ::TwoFactorAuthentication
##
# Verify the validity of the entered token
def confirm_otp
- login_if_otp_token_valid(@authenticated_user, params[:otp])
+ login_if_otp_token_valid(
+ user: @authenticated_user,
+ otp_token: params[:otp],
+ webauthn_credential: params[:webauthn_credential]
+ )
end
##
@@ -51,6 +55,15 @@ module ::TwoFactorAuthentication
perform_2fa_authentication service
end
+ def webauthn_challenge
+ device = otp_service(@authenticated_user).device
+
+ webauthn_options = device.options_for_get
+ session[:webauthn_challenge] = webauthn_options.challenge
+
+ render json: webauthn_options
+ end
+
private
##
@@ -137,9 +150,14 @@ module ::TwoFactorAuthentication
##
# Check OTP string and login if valid
- def login_if_otp_token_valid(user, token_string)
+ def login_if_otp_token_valid(user:, otp_token:, webauthn_credential:)
service = otp_service_for_verification(user)
- result = service.verify(token_string)
+
+ result = if service.device.class.device_type == :webauthn
+ service.verify(webauthn_credential, webauthn_challenge: session[:webauthn_challenge])
+ else
+ service.verify(otp_token)
+ end
if result.success?
set_remember_token!
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 531ae51acdf..f8c74f9fb6c 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
@@ -1,6 +1,6 @@
module TwoFactorAuthentication
class Device::Webauthn < Device
- validates :webauthn_external_id, presence: true, uniqueness: true
+ validates :webauthn_external_id, presence: true, uniqueness: { scoped_to: :user_id }
validates :webauthn_public_key, presence: true
# Check allowed channels
diff --git a/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb b/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb
index 09c6bbdf3d4..f8e8e021f18 100644
--- a/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb
+++ b/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb
@@ -57,17 +57,17 @@ module TwoFactorAuthentication
##
# Validate a token that was input by the user
- def verify(input_token)
+ def verify(input, **options)
# Validate that we can request the token for this user
# and get the matching strategy we will use
verify_device_and_strategy
# Produce the token with the given strategy (e.g., sending an sms)
- result = strategy.verify input_token
+ result = strategy.verify(input, **options)
ServiceResult.new(success: result)
rescue StandardError => e
- Rails.logger.error "[2FA plugin] Error during token validation for user##{user.id}: #{e}"
+ Rails.logger.error "[2FA plugin] Error during token validation for user##{user.id}: #{e.class} #{e}"
result = ServiceResult.failure
result.errors.add(:base, e.message)
diff --git a/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb b/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb
index d1ff47bdd28..9d53a8024a7 100644
--- a/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb
+++ b/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb
@@ -11,7 +11,12 @@
<%= styled_form_tag(
{ action: :confirm_otp },
id: 'submit_otp',
- autocomplete: "off") do %>
+ autocomplete: "off", data: {
+ controller: "two-factor-authentication",
+ application_target: "dynamic",
+ challenge_url: url_for(action: :webauthn_challenge, format: :json),
+ device_type: @used_device.class.device_type,
+ action: "submit->two-factor-authentication#onVerifyDevice"}) do %>
<%= back_url_hidden_field_tag %>
<h2><%= t 'two_factor_authentication.label_two_factor_authentication' %></h2>
<% identifier = @used_device.request_2fa_identifier(@strategy.channel) %>
@@ -27,6 +32,7 @@
<% else %>
<p><%= raw I18n.t('two_factor_authentication.devices.2fa_from_webauthn', device_name: identifier) %></p>
<hr class="form--separator">
+ <%= hidden_field_tag 'webauthn_credential', nil, "data-two-factor-authentication-target": "webauthnCredential" %>
<% end %>
<% if remember_2fa_enabled? %>
<div class="form--field -wide-label">
diff --git a/modules/two_factor_authentication/config/locales/en.yml b/modules/two_factor_authentication/config/locales/en.yml
index 51edc1ab798..9b4971fc754 100644
--- a/modules/two_factor_authentication/config/locales/en.yml
+++ b/modules/two_factor_authentication/config/locales/en.yml
@@ -10,14 +10,14 @@ en:
activerecord:
attributes:
two_factor_authentication/device:
- identifier: 'Identifier'
- default: 'Use as default'
+ identifier: "Identifier"
+ default: "Use as default"
two_factor_authentication/device/sms:
phone_number: "Phone number"
errors:
models:
two_factor_authentication/device:
- default_already_exists: 'is already set for another OTP device.'
+ default_already_exists: "is already set for another OTP device."
two_factor_authentication/device/sms:
attributes:
phone_number:
@@ -32,8 +32,8 @@ en:
error_2fa_disabled: "2FA delivery has been disabled."
error_no_device: "No registered 2FA device found for this user, despite being required for this instance."
error_no_matching_strategy: "No matching 2FA strategy available for this user. Please contact your administratior."
- error_is_enforced_not_active: 'Configuration error: Two-factor authentication has been enforced, but no active strategies exist.'
- error_invalid_backup_code: 'Invalid 2FA backup code'
+ error_is_enforced_not_active: "Configuration error: Two-factor authentication has been enforced, but no active strategies exist."
+ error_invalid_backup_code: "Invalid 2FA backup code"
channel_unavailable: "The delivery channel %{channel} is unavailable."
no_valid_phone_number: "No valid phone number exists."
label_pwd_confirmation: "Password"
@@ -42,47 +42,47 @@ en:
label_default_device: "Default 2FA device"
label_device: "2FA device"
label_devices: "2FA devices"
- label_one_time_password: 'One-time password'
- label_2fa_enabled: 'Two-factor authentication is active'
- label_2fa_disabled: 'Two-factor authentication not active'
+ label_one_time_password: "One-time password"
+ label_2fa_enabled: "Two-factor authentication is active"
+ label_2fa_disabled: "Two-factor authentication not active"
text_otp_delivery_message_sms: "Your %{app_title} one-time password is %{token}"
text_otp_delivery_message_voice: "Your %{app_title} one-time password is: %{pause} %{token}. %{pause} I repeat: %{pause} %{token}"
- text_enter_2fa: 'Please enter the one-time password from your device.'
- text_2fa_enabled: 'Upon every login, you will be requested to enter a OTP token from your default 2FA device.'
- text_2fa_disabled: 'To enable two-factor authentication, use the button above to register a new 2FA device. If you already have a device, you need to make it a default.'
+ text_enter_2fa: "Please enter the one-time password from your device."
+ text_2fa_enabled: "Upon every login, you will be requested to enter a OTP token from your default 2FA device."
+ text_2fa_disabled: "To enable two-factor authentication, use the button above to register a new 2FA device. If you already have a device, you need to make it a default."
login:
enter_backup_code_title: Enter backup code
enter_backup_code_text: Please enter a valid backup code from your list of codes in case you can no longer access your registered 2FA devices.
- other_device: 'Use another device or backup code'
+ other_device: "Use another device or backup code"
settings:
- title: '2FA settings'
- current_configuration: 'Current configuration'
- label_active_strategies: 'Active 2FA strategies'
- label_enforced: 'Enforce 2FA'
- label_remember: 'Remember 2FA login'
+ title: "2FA settings"
+ current_configuration: "Current configuration"
+ label_active_strategies: "Active 2FA strategies"
+ label_enforced: "Enforce 2FA"
+ label_remember: "Remember 2FA login"
text_configuration: |
Note: These values represent the current application-wide configuration. You cannot disable settings enforced by the configuration or change the current active strategies, since they require a server restart.
text_configuration_guide: For more information, check the configuration guide.
- text_enforced: 'Enable this setting to force all users to register a 2FA device on their next login. Can only be disabled when not enforced by configuration.'
+ text_enforced: "Enable this setting to force all users to register a 2FA device on their next login. Can only be disabled when not enforced by configuration."
text_remember: |
Set this to greater than zero to allow users to remember their 2FA authentication for the given number of days.
They will not be requested to re-enter it during that period. Can only be set when not enforced by configuration.
- error_invalid_settings: 'The 2FA strategies you selected are invalid'
- failed_to_save_settings: 'Failed to update 2FA settings: %{message}'
+ error_invalid_settings: "The 2FA strategies you selected are invalid"
+ failed_to_save_settings: "Failed to update 2FA settings: %{message}"
admin:
- self_edit_path: 'To add or modify your own 2FA devices, please go to %{self_edit_link}'
- self_edit_link_name: 'Two-factor authentication on your account page'
- self_edit_forbidden: 'You may not edit your own 2FA devices on this path. Go to My Account > Two factor authentication instead.'
- no_devices_for_user: 'No 2FA device has been registered for this user.'
- all_devices_deleted: 'All 2FA devices of this user have been deleted'
- delete_all_are_you_sure: 'Are you sure you want to delete all 2FA devices for this user?'
- button_delete_all_devices: 'Delete registered 2FA devices'
- button_register_mobile_phone_for_user: 'Register mobile phone'
- text_2fa_enabled: 'Upon every login, this user will be requested to enter a OTP token from their default 2FA device.'
+ self_edit_path: "To add or modify your own 2FA devices, please go to %{self_edit_link}"
+ self_edit_link_name: "Two-factor authentication on your account page"
+ self_edit_forbidden: "You may not edit your own 2FA devices on this path. Go to My Account > Two factor authentication instead."
+ no_devices_for_user: "No 2FA device has been registered for this user."
+ all_devices_deleted: "All 2FA devices of this user have been deleted"
+ delete_all_are_you_sure: "Are you sure you want to delete all 2FA devices for this user?"
+ button_delete_all_devices: "Delete registered 2FA devices"
+ button_register_mobile_phone_for_user: "Register mobile phone"
+ text_2fa_enabled: "Upon every login, this user will be requested to enter a OTP token from their default 2FA device."
text_2fa_disabled: "The user did not set up a 2FA device through their 'My account page'"
upsale:
- title: 'Two-factor authentication'
- description: 'Strenghten the security of your OpenProject instance by offering (or enforcing) two-factor authentification to all project members.'
+ title: "Two-factor authentication"
+ description: "Strenghten the security of your OpenProject instance by offering (or enforcing) two-factor authentification to all project members."
backup_codes:
none_found: No backup codes exist for this account.
singular: Backup code
@@ -93,42 +93,42 @@ en:
Use the following button to generate a new set of backup codes.
generate:
title: Generate backup codes
- keep_safe_as_password: 'Important! Treat these codes as passwords.'
- keep_safe_warning: 'Either save them in your password manager, or print this page and put in a safe place.'
- regenerate_warning: 'Warning: If you have created backup codes before, they will be invalidated and will no longer work.'
+ keep_safe_as_password: "Important! Treat these codes as passwords."
+ keep_safe_warning: "Either save them in your password manager, or print this page and put in a safe place."
+ regenerate_warning: "Warning: If you have created backup codes before, they will be invalidated and will no longer work."
devices:
- add_new: 'Add new 2FA device'
- register: 'Register device'
- confirm_default: 'Confirm changing default device'
- confirm_device: 'Confirm device'
- confirm_now: 'Not confirmed, click here to activate'
- cannot_delete_default: 'Cannot delete default device'
- make_default_are_you_sure: 'Are you sure you want to make this 2FA device your default?'
- make_default_failed: 'Failed to update the default 2FA device.'
- deletion_are_you_sure: 'Are you sure you want to delete this 2FA device?'
- registration_complete: '2FA device registration complete!'
- registration_failed_token_invalid: '2FA device registration failed, the token was invalid.'
- registration_failed_update: '2FA device registration failed, the token was valid but the device could not be updated.'
- confirm_send_failed: 'Confirmation of your 2FA device failed.'
- button_complete_registration: 'Complete 2FA registration'
+ add_new: "Add new 2FA device"
+ register: "Register device"
+ confirm_default: "Confirm changing default device"
+ confirm_device: "Confirm device"
+ confirm_now: "Not confirmed, click here to activate"
+ cannot_delete_default: "Cannot delete default device"
+ make_default_are_you_sure: "Are you sure you want to make this 2FA device your default?"
+ make_default_failed: "Failed to update the default 2FA device."
+ deletion_are_you_sure: "Are you sure you want to delete this 2FA device?"
+ registration_complete: "2FA device registration complete!"
+ registration_failed_token_invalid: "2FA device registration failed, the token was invalid."
+ registration_failed_update: "2FA device registration failed, the token was valid but the device could not be updated."
+ confirm_send_failed: "Confirmation of your 2FA device failed."
+ button_complete_registration: "Complete 2FA registration"
text_confirm_to_complete_html: "Please complete the registration of your device <strong>%{identifier}</strong> by entering a one-time password from your default device."
text_confirm_to_change_default_html: "Please confirm changing your default device to <strong>%{new_identifier}</strong> by entering a one-time password from your current default device."
- text_identifier: 'You can give the device a custom identifier using this field.'
- failed_to_delete: 'Failed to delete 2FA device.'
- is_default_cannot_delete: 'The device is marked as default and cannot be deleted due to an active security policy. Mark another device as default before deleting.'
- not_existing: 'No 2FA device has been registered for your account.'
+ text_identifier: "You can give the device a custom identifier using this field."
+ failed_to_delete: "Failed to delete 2FA device."
+ is_default_cannot_delete: "The device is marked as default and cannot be deleted due to an active security policy. Mark another device as default before deleting."
+ not_existing: "No 2FA device has been registered for your account."
2fa_from_input: Please enter the code from your <strong>%{device_name}</strong> to verify your identity.
- 2fa_from_webauthn: Please provide the WebAuthn device <strong>%{device_name}</strong>. If it is USB based make sure to plug it in and touch it.
+ 2fa_from_webauthn: Please provide the WebAuthn device <strong>%{device_name}</strong>. If it is USB based make sure to plug it in and touch it. Then click the sign in button.
webauthn:
- title: 'WebAuthn'
+ title: "WebAuthn"
description: Use Web Authentication to register a FIDO2 device (like a YubiKey) or the secure enclave of your mobile device as a second factor.
totp:
- title: 'Use your app-based authenticator'
- provisioning_uri: 'Provisioning URI'
- secret_key: 'Secret key'
- time_based: 'Time based'
- account: 'Account name / Issuer'
+ title: "Use your app-based authenticator"
+ provisioning_uri: "Provisioning URI"
+ secret_key: "Secret key"
+ time_based: "Time based"
+ account: "Account name / Issuer"
setup: |
For setting up two-factor authentication with Google Authenticator, download the application from the Apple App store or Google Play Store.
After opening the app, you can scan the following QR code to register the device.
@@ -140,38 +140,37 @@ en:
Register an application authenticator for use with OpenProject using the time-based one-time password authentication standard.
Common examples are Google Authenticator or Authy.
sms:
- title: 'Use your mobile phone'
- redacted_identifier: 'Mobile device (%{redacted_number})'
- request_2fa_identifier: '%{redacted_identifier}, we sent you an authentication code via %{delivery_channel}'
+ title: "Use your mobile phone"
+ redacted_identifier: "Mobile device (%{redacted_number})"
+ request_2fa_identifier: "%{redacted_identifier}, we sent you an authentication code via %{delivery_channel}"
description: |
Register your mobile phone number for delivery of OpenProject one-time passwords.
sns:
- delivery_failed: 'SNS delivery failed:'
+ delivery_failed: "SNS delivery failed:"
message_bird:
- sms_delivery_failed: 'MessageBird SMS delivery failed.'
- voice_delivery_failed: 'MessageBird voice call failed.'
+ sms_delivery_failed: "MessageBird SMS delivery failed."
+ voice_delivery_failed: "MessageBird voice call failed."
strategies:
- totp: 'Authenticator application'
- sns: 'Amazon SNS'
- resdt: 'SMS Rest API'
- webauthn: 'WebAuthn'
+ totp: "Authenticator application"
+ sns: "Amazon SNS"
+ resdt: "SMS Rest API"
+ webauthn: "WebAuthn"
mobile_transmit_notification: "A one-time password has been sent to your cell phone."
- label_two_factor_authentication: 'Two-factor authentication'
+ label_two_factor_authentication: "Two-factor authentication"
forced_registration:
- required_to_add_device: 'An active security policy requires you to enable two-factor authentication. Please use the following form to register a device.'
+ required_to_add_device: "An active security policy requires you to enable two-factor authentication. Please use the following form to register a device."
remember:
active_session_notice: >
Your account has an active remember cookie valid until %{expires_on}.
This cookie allows you to log in without a second factor to your account until that time.
- other_active_session_notice:
- Your account has an active remember cookie on another session.
- label: 'Remember'
- clear_cookie: 'Click here to remove all remembered 2FA sessions.'
- cookie_removed: 'All remembered 2FA sessions have been removed.'
+ other_active_session_notice: Your account has an active remember cookie on another session.
+ label: "Remember"
+ clear_cookie: "Click here to remove all remembered 2FA sessions."
+ cookie_removed: "All remembered 2FA sessions have been removed."
dont_ask_again: "Create cookie to remember 2FA authentication on this client for %{days} days."
field_phone: "Cell phone"
field_otp: "One-time password"
@@ -181,10 +180,10 @@ en:
notice_account_otp_send_failed: "Your one-time password could not be sent."
notice_account_has_no_phone: "No cell phone number is associated with your account."
label_expiration_hint: "%{date} or on logout"
- label_actions: 'Actions'
- label_confirmed: 'Confirmed'
- button_continue: 'Continue'
- button_make_default: 'Mark as default'
+ label_actions: "Actions"
+ label_confirmed: "Confirmed"
+ button_continue: "Continue"
+ button_make_default: "Mark as default"
label_unverified_phone: "Cell phone not yet verified"
notice_phone_number_format: "Please enter the number in the following format: +XX XXXXXXXX."
text_otp_not_receive: "Other verification methods"
diff --git a/modules/two_factor_authentication/config/routes.rb b/modules/two_factor_authentication/config/routes.rb
index eb927f54762..d28379b9bd8 100644
--- a/modules/two_factor_authentication/config/routes.rb
+++ b/modules/two_factor_authentication/config/routes.rb
@@ -8,6 +8,9 @@ Rails.application.routes.draw do
get :settings, to: 'two_factor_settings#show', as: 'settings_2fa'
post :settings, to: 'two_factor_settings#update', as: 'update_settings_2fa'
+
+ # Request a challenge for WebAuthn
+ get :webauthn_challenge, to: 'authentication#webauthn_challenge', as: 'webauthn_challenge'
end
scope 'two_factor_authentication' do # Avoids adding the namespace prefix
diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb
index 3f6bff7fa0a..f17222a067e 100644
--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb
+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb
@@ -14,7 +14,7 @@ module OpenProject::TwoFactorAuthentication
@device = device
end
- def verify(input_token)
+ def verify(input_token, **)
# Ensure this strategy uses mobile tokens or overrode this method
raise 'Cannot verify mobile token' unless self.class.mobile_token?
diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb
index c1f59156c5c..69acd0731ed 100644
--- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb
+++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/webauthn.rb
@@ -3,22 +3,17 @@ require 'webauthn'
module OpenProject::TwoFactorAuthentication
module TokenStrategy
class Webauthn < Base
- def verify(webauthn_params)
- webauthn_credential = WebAuthn::Credential.from_get(webauthn_params)
-
- # TODO: Device finding can happen by the provided ID
-
- # TODO: Access session
- authentication_challenge = "foo"
+ def verify(webauthn_credential, webauthn_challenge:)
+ credential = WebAuthn::Credential.from_get(JSON.parse(webauthn_credential))
# This will raise WebAuthn::Error
- webauthn_credential.verify(
- authentication_challenge,
+ credential.verify(
+ webauthn_challenge,
public_key: device.webauthn_public_key,
sign_count: device.webauthn_sign_count
)
- device.update!(webauthn_sign_count: webauthn_credential.sign_count)
+ device.update!(webauthn_sign_count: credential.sign_count)
true
end