Files
fizzy/app/controllers/sessions/passkeys_controller.rb
T
Stanko K.R. fbe9252db1 Auto-suggest name for new Passkeys
- Use plain client data json everywhere
- Expose AAGUID and backed_up on Credentials
- Make attestation verifiers configurable
- Auto-suggest names for passkeys and show icons
2026-03-18 11:49:59 +01:00

51 lines
1.5 KiB
Ruby

class Sessions::PasskeysController < ApplicationController
disallow_account_scope
require_unauthenticated_access
rate_limit to: 10, within: 3.minutes, only: :create, with: :rate_limit_exceeded
def create
credential = Identity::Credential.authenticate(
passkey: passkey_params,
challenge: session.delete(:webauthn_challenge)
)
if credential
authentication_succeeded(credential.identity)
else
authentication_failed
end
end
private
def passkey_params
params.expect(passkey: [ :id, :client_data_json, :authenticator_data, :signature ])
end
def authentication_succeeded(identity)
start_new_session_for identity
respond_to do |format|
format.html { redirect_to after_authentication_url }
format.json { render json: { session_token: session_token } }
end
end
def authentication_failed
alert_message = "That passkey didn't work. Try again."
respond_to do |format|
format.html { redirect_to new_session_path, alert: alert_message }
format.json { render json: { message: alert_message }, status: :unauthorized }
end
end
def rate_limit_exceeded
rate_limit_exceeded_message = "Try again later."
respond_to do |format|
format.html { redirect_to new_session_path, alert: rate_limit_exceeded_message }
format.json { render json: { message: rate_limit_exceeded_message }, status: :too_many_requests }
end
end
end