Class: PasskeysRails::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/passkeys_rails/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



49
50
51
52
53
54
55
56
# File 'lib/passkeys_rails/configuration.rb', line 49

def initialize
  # defaults
  @auth_token_secret = Rails.application.secret_key_base
  @auth_token_algorithm = "HS256"
  @auth_token_expires_in = 30.days
  @default_class = "User"
  @wa_origin = "https://example.com"
end

Instance Attribute Details

#auth_token_algorithmObject

Algorithm used to generate the auth token. Changing this value will invalidate all tokens that have been fetched through the API.



12
13
14
# File 'lib/passkeys_rails/configuration.rb', line 12

def auth_token_algorithm
  @auth_token_algorithm
end

#auth_token_expires_inObject

How long the auth token is valid before requiring a refresh or new login. Set it to 0 for no expiration (not recommended in production).



16
17
18
# File 'lib/passkeys_rails/configuration.rb', line 16

def auth_token_expires_in
  @auth_token_expires_in
end

#auth_token_secretObject

Secret used to encode the auth token. Rails.application.secret_key_base is used if none is defined here. Changing this value will invalidate all tokens that have been fetched through the API.



7
8
9
# File 'lib/passkeys_rails/configuration.rb', line 7

def auth_token_secret
  @auth_token_secret
end

#class_whitelistObject

By providing a class_whitelist, the API will require that any supplied class is in the whitelist. If it is not, the auth API will return an error. This prevents a caller from attempting to create an unintended record on registration. If nil, any model will be allowed. If [], no model will be allowed. This should be an array of symbols or strings, for example: %w[User AdminUser]



38
39
40
# File 'lib/passkeys_rails/configuration.rb', line 38

def class_whitelist
  @class_whitelist
end

#default_classObject

Model to use when creating or authenticating a passkey. This can be overridden when calling the API, but if no value is supplied when calling the API, this value is used. If nil, there is no default, and if none is supplied when calling the API, no resource is created other than a PaskeysRails::Agent that is used to track the passkey.

This library doesn’t assume that there will only be one model, but it is a common use case, so setting the default_class simplifies the use of the API in that case.



28
29
30
# File 'lib/passkeys_rails/configuration.rb', line 28

def default_class
  @default_class
end

#wa_algorithmObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_algorithm
  @wa_algorithm
end

#wa_algorithmsObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_algorithms
  @wa_algorithms
end

#wa_credential_options_timeoutObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_credential_options_timeout
  @wa_credential_options_timeout
end

#wa_encodingObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_encoding
  @wa_encoding
end

#wa_originObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_origin
  @wa_origin
end

#wa_relying_party_nameObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_relying_party_name
  @wa_relying_party_name
end

#wa_rp_idObject

webauthn settings



41
42
43
# File 'lib/passkeys_rails/configuration.rb', line 41

def wa_rp_id
  @wa_rp_id
end

Instance Method Details

#subscribe(event_name) ⇒ Object



58
59
60
# File 'lib/passkeys_rails/configuration.rb', line 58

def subscribe(event_name)
  PasskeysRails.subscribe(event_name)
end