Module: Unmagic::Passkeys::Holder

Extended by:
ActiveSupport::Concern
Defined in:
lib/unmagic/passkeys/holder.rb

Overview

Adds passkey support to an Active Record model (the “holder” of passkeys).

Usage

class User < ApplicationRecord
  has_passkeys name: :email_address, display_name: :name
end

This sets up a polymorphic has_many :passkeys association and defines two methods on the model that supply holder-specific options for the WebAuthn ceremonies:

  • passkey_registration_options — merged into Unmagic::Passkeys::Credential.registration_options

  • passkey_authentication_options — merged into Unmagic::Passkeys::Credential.authentication_options

Options

has_passkeys accepts keyword arguments that map to WebAuthn creation or request option fields. Values can be symbols (sent to the record), procs (evaluated in the record’s context), or plain values:

name

A human-readable account identifier (typically an email or username) shown by the authenticator when the user selects a passkey. Maps to the WebAuthn user.name field.

display_name

A friendly label for the user (typically their full name) shown by the authenticator during passkey registration. Maps to the WebAuthn user.displayName field.

has_passkeys name: :email, display_name: :name

For more complex configuration, pass a block that receives a Unmagic::Passkeys::Holder::Config:

has_passkeys do |config|
  config.registration_options { { name: email, display_name: name } }
  config.authentication_options { { user_verification: "required" } }
end

Defined Under Namespace

Classes: Config