Class: Passkeyed::Credential
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Passkeyed::Credential
- Defined in:
- lib/passkeyed/credential.rb,
sig/passkeyed/credential.rbs
Overview
Inherits Passkeyed.base_record_class (ApplicationRecord / ActiveRecord::Base) at load time; declared here against ActiveRecord::Base for typing.
Instance Method Summary collapse
-
#record_sign_in!(new_sign_count, backed_up: nil) ⇒ void
Persist the state a successful assertion produces: the advanced signature counter, and — when the columns are present — a last-used timestamp and the current backup state (a device-bound passkey may later start syncing, flipping the flag).
-
#transports ⇒ Array[String]?
transportsis stored as a JSON string (portable across databases); expose it as the Array WebAuthn reported, e.g. - #transports=(value) ⇒ Object
Instance Method Details
#record_sign_in!(new_sign_count, backed_up: nil) ⇒ void
This method returns an undefined value.
Persist the state a successful assertion produces: the advanced signature counter, and — when the columns are present — a last-used timestamp and the current backup state (a device-bound passkey may later start syncing, flipping the flag). The columns are guarded so authentication keeps working on apps that trimmed the optional columns from the migration.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/passkeyed/credential.rb', line 31 def record_sign_in!(new_sign_count, backed_up: nil) attributes = { sign_count: new_sign_count } attributes[:last_used_at] = Time.current if has_attribute?(:last_used_at) attributes[:backed_up] = backed_up if !backed_up.nil? && has_attribute?(:backed_up) assign_attributes(attributes) # Everything written here is server-derived, so skip validations: a record # invalid by rules added after it was persisted (e.g. a nickname cap # introduced in a future version) must not start failing every sign-in. save!(validate: false) end |
#transports ⇒ Array[String]?
transports is stored as a JSON string (portable across databases);
expose it as the Array WebAuthn reported, e.g. ["internal", "hybrid"].
Unparseable stored data (a manual write, a botched import) reads as nil
rather than raising out of every page that lists credentials.
46 47 48 49 50 51 |
# File 'lib/passkeyed/credential.rb', line 46 def transports raw = super raw.is_a?(String) ? JSON.parse(raw) : raw rescue JSON::ParserError nil end |
#transports=(value) ⇒ Object
53 54 55 56 |
# File 'lib/passkeyed/credential.rb', line 53 def transports=(value) value = JSON.generate(value) unless value.nil? || value.is_a?(String) super end |