Class: WebAuthn::CredentialCreationOptions

Inherits:
CredentialOptions show all
Defined in:
lib/webauthn/credential_creation_options.rb

Constant Summary collapse

DEFAULT_RP_NAME =
"web-server"

Constants inherited from CredentialOptions

WebAuthn::CredentialOptions::CHALLENGE_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CredentialOptions

#challenge, #timeout

Constructor Details

#initialize(attestation: nil, authenticator_selection: nil, exclude_credentials: nil, extensions: nil, user_id:, user_name:, user_display_name: nil, rp_name: nil) ⇒ CredentialCreationOptions

Returns a new instance of CredentialCreationOptions.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/webauthn/credential_creation_options.rb', line 25

def initialize(
  attestation: nil,
  authenticator_selection: nil,
  exclude_credentials: nil,
  extensions: nil,
  user_id:,
  user_name:,
  user_display_name: nil,
  rp_name: nil
)
  super()

  @attestation = attestation
  @authenticator_selection = authenticator_selection
  @exclude_credentials = exclude_credentials
  @extensions = extensions
  @user_id = user_id
  @user_name = user_name
  @user_display_name = user_display_name
  @rp_name = rp_name
end

Instance Attribute Details

#attestationObject

Returns the value of attribute attestation.



23
24
25
# File 'lib/webauthn/credential_creation_options.rb', line 23

def attestation
  @attestation
end

#authenticator_selectionObject

Returns the value of attribute authenticator_selection.



23
24
25
# File 'lib/webauthn/credential_creation_options.rb', line 23

def authenticator_selection
  @authenticator_selection
end

#exclude_credentialsObject

Returns the value of attribute exclude_credentials.



23
24
25
# File 'lib/webauthn/credential_creation_options.rb', line 23

def exclude_credentials
  @exclude_credentials
end

#extensionsObject

Returns the value of attribute extensions.



23
24
25
# File 'lib/webauthn/credential_creation_options.rb', line 23

def extensions
  @extensions
end

Instance Method Details

#pub_key_cred_paramsObject



75
76
77
78
79
# File 'lib/webauthn/credential_creation_options.rb', line 75

def pub_key_cred_params
  configuration.algorithms.map do |alg_name|
    { type: "public-key", alg: COSE::Algorithm.by_name(alg_name).id }
  end
end

#rpObject



81
82
83
# File 'lib/webauthn/credential_creation_options.rb', line 81

def rp
  @rp ||= CredentialRPEntity.new(name: rp_name || configuration.rp_name || DEFAULT_RP_NAME)
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/webauthn/credential_creation_options.rb', line 47

def to_h
  options = {
    challenge: challenge,
    pubKeyCredParams: pub_key_cred_params,
    timeout: timeout,
    user: { id: user.id, name: user.name, displayName: user.display_name },
    rp: { name: rp.name }
  }

  if attestation
    options[:attestation] = attestation
  end

  if authenticator_selection
    options[:authenticatorSelection] = authenticator_selection
  end

  if exclude_credentials
    options[:excludeCredentials] = exclude_credentials
  end

  if extensions
    options[:extensions] = extensions
  end

  options
end

#userObject



85
86
87
# File 'lib/webauthn/credential_creation_options.rb', line 85

def user
  @user ||= CredentialUserEntity.new(id: user_id, name: user_name, display_name: user_display_name)
end