Class: PasskeyAuth::Webauthn::Authentications::ChallengesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/passkey_auth/webauthn/authentications/challenges_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/passkey_auth/webauthn/authentications/challenges_controller.rb', line 14

def create
  if @user
    # Prepare the needed data for a challenge
    options = ::WebAuthn::Credential.options_for_get(allow: @user.webauthn_credentials.pluck(:external_id))
  else
    # For conditional UI, we create options for authentication without knowing the user ahead of time
    # This allows the browser to prompt with available passkeys
    options = ::WebAuthn::Credential.options_for_get(user_verification: "required")
  end

  # Generate the challenge and save it into the session
  session[:webauthn_authentication_challenge] = options.challenge

  respond_to do |format|
    format.json { render json: options }
  end
end