# View helpers for rendering passkey forms and meta tags. # # Include this module in your helper or ApplicationHelper to get access to: # # - +passkey_creation_options_meta_tag+ / +passkey_request_options_meta_tag+ — render a # tag containing the JSON-serialized WebAuthn options for the browser credential API. # - +passkey_creation_button+ — render a form with hidden fields for the registration ceremony. # - +passkey_sign_in_button+ — render a form with hidden fields for the authentication # ceremony. module ActionPack::Passkey::FormHelper # Renders ++ tags containing JSON-serialized creation options and the challenge endpoint # URL for the WebAuthn registration ceremony. The companion JavaScript reads these tags to call # +navigator.credentials.create()+. def passkey_creation_options_meta_tag(creation_options, challenge_url: nil) passkey_challenge_url_meta_tag(challenge_url: challenge_url) + tag.meta(name: "passkey-creation-options", content: creation_options.to_json) end # Renders ++ tags containing JSON-serialized request options and the challenge endpoint # URL for the WebAuthn authentication ceremony. The companion JavaScript reads these tags to # call +navigator.credentials.get()+. def passkey_request_options_meta_tag(request_options, challenge_url: nil) passkey_challenge_url_meta_tag(challenge_url: challenge_url) + tag.meta(name: "passkey-request-options", content: request_options.to_json) end # Renders a form with hidden fields for the passkey registration ceremony. The form POSTs to # +url+ and includes hidden fields for +client_data_json+, +attestation_object+, and # +transports+ — populated by the Stimulus controller after the browser credential API # resolves. Accepts a +label+ string or a block for button content. # # Options: # - +param+: the form parameter namespace (default: +:passkey+) # - +form+: additional HTML attributes for the +