lib/webauthn/credential_creation_options.rb in webauthn-1.15.0 vs lib/webauthn/credential_creation_options.rb in webauthn-1.16.0

- old
+ new

@@ -12,34 +12,64 @@ rp_name: rp_name, user_id: user_id, user_name: user_name, user_display_name: display_name ).to_h end class CredentialCreationOptions < CredentialOptions - DEFAULT_ALGORITHMS = ["ES256", "RS256"].freeze DEFAULT_RP_NAME = "web-server" - DEFAULT_PUB_KEY_CRED_PARAMS = DEFAULT_ALGORITHMS.map do |alg_name| - { type: "public-key", alg: COSE::Algorithm.by_name(alg_name).id } - end.freeze + attr_accessor :attestation, :authenticator_selection, :exclude_credentials, :extensions - def initialize(user_id:, user_name:, user_display_name: nil, rp_name: nil) + def initialize( + attestation: nil, + authenticator_selection: nil, + exclude_credentials: nil, + extensions: nil, + user_id:, + user_name:, + user_display_name: nil, + rp_name: nil + ) + @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 def to_h - { + options = { challenge: challenge, pubKeyCredParams: pub_key_cred_params, 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 def pub_key_cred_params - DEFAULT_PUB_KEY_CRED_PARAMS + WebAuthn.configuration.algorithms.map do |alg_name| + { type: "public-key", alg: COSE::Algorithm.by_name(alg_name).id } + end end def rp @rp ||= CredentialRPEntity.new(name: rp_name || configuration.rp_name || DEFAULT_RP_NAME) end