class WebAuthn::PublicKeyCredential::Options

Constants

CHALLENGE_LENGTH

Attributes

extensions[R]
timeout[R]

Public Class Methods

new(timeout: default_timeout, extensions: nil) click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 13
def initialize(timeout: default_timeout, extensions: nil)
  @timeout = timeout
  @extensions = extensions
end

Public Instance Methods

as_json(*) click to toggle source

Argument wildcard for Ruby on Rails controller automatic object JSON serialization

# File lib/webauthn/public_key_credential/options.rb, line 23
def as_json(*)
  to_hash.to_camelback_keys
end
challenge() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 18
def challenge
  encoder.encode(raw_challenge)
end

Private Instance Methods

as_public_key_descriptors(ids) click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 67
def as_public_key_descriptors(ids)
  Array(ids).map { |id| { type: TYPE_PUBLIC_KEY, id: id } }
end
attributes() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 47
def attributes
  [:challenge, :timeout, :extensions]
end
configuration() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 63
def configuration
  WebAuthn.configuration
end
default_timeout() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 59
def default_timeout
  configuration.credential_options_timeout
end
encoder() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 51
def encoder
  WebAuthn.configuration.encoder
end
raw_challenge() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 55
def raw_challenge
  @raw_challenge ||= SecureRandom.random_bytes(CHALLENGE_LENGTH)
end
to_hash() click to toggle source
# File lib/webauthn/public_key_credential/options.rb, line 29
def to_hash
  hash = {}

  attributes.each do |attribute_name|
    value = send(attribute_name)

    if value.respond_to?(:as_json)
      value = value.as_json
    end

    if value
      hash[attribute_name] = value
    end
  end

  hash
end