Class: Admin::PasskeyRegistrationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Admin::PasskeyRegistrationsController
- Includes:
- SudoMode
- Defined in:
- lib/generators/ruby_cms/templates/controllers/admin/passkey_registrations_controller.rb
Constant Summary
Constants included from SudoMode
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/passkey_registration — verify attestation, store credential.
-
#new ⇒ Object
GET — the "name your passkey + register" page.
-
#options ⇒ Object
POST /admin/passkey_registration/options — issue WebAuthn creation options.
Methods inherited from ApplicationController
#admin_notifications, cms_page, #current_user_cms
Instance Method Details
#create ⇒ Object
POST /admin/passkey_registration — verify attestation, store credential.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/ruby_cms/templates/controllers/admin/passkey_registrations_controller.rb', line 27 def create raw = params[:credential] return render(json: { error: "Missing credential" }, status: :bad_request) if raw.blank? webauthn_credential = WebAuthn::Credential.from_create(raw.to_unsafe_h) challenge = session.delete(:passkey_registration_challenge) webauthn_credential.verify(challenge) Current.user.passkey_credentials.create!( external_id: webauthn_credential.id, public_key: webauthn_credential.public_key, sign_count: webauthn_credential.sign_count, nickname: params[:nickname].presence || "Passkey", transports: Array(params[:transports]).join(","), last_used_at: nil ) render json: { ok: true, redirect: admin_user_path(Current.user, tab: "passkeys") } rescue WebAuthn::Error => e render json: { error: e. }, status: :unprocessable_entity rescue ArgumentError, JSON::ParserError => e render json: { error: "Invalid credential format" }, status: :bad_request end |
#new ⇒ Object
GET — the "name your passkey + register" page.
11 12 |
# File 'lib/generators/ruby_cms/templates/controllers/admin/passkey_registrations_controller.rb', line 11 def new end |
#options ⇒ Object
POST /admin/passkey_registration/options — issue WebAuthn creation options.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/ruby_cms/templates/controllers/admin/passkey_registrations_controller.rb', line 15 def user = Current.user = WebAuthn::Credential.( user: { id: user.webauthn_id, name: user.email_address, display_name: user.email_address }, exclude: user.passkey_credentials.pluck(:external_id), authenticator_selection: { resident_key: "preferred", user_verification: "preferred" } ) session[:passkey_registration_challenge] = .challenge render json: end |