Class: WebAuthn::ClientData

Inherits:
Object
  • Object
show all
Defined in:
lib/webauthn/client_data.rb

Constant Summary collapse

VALID_TOKEN_BINDING_STATUSES =
["present", "supported", "not-supported"].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client_data_json) ⇒ ClientData

Returns a new instance of ClientData.



14
15
16
# File 'lib/webauthn/client_data.rb', line 14

def initialize(client_data_json)
  @client_data_json = client_data_json
end

Instance Method Details

#challengeObject



22
23
24
# File 'lib/webauthn/client_data.rb', line 22

def challenge
  WebAuthn.standard_encoder.decode(data["challenge"])
end

#hashObject



42
43
44
# File 'lib/webauthn/client_data.rb', line 42

def hash
  OpenSSL::Digest::SHA256.digest(client_data_json)
end

#originObject



26
27
28
# File 'lib/webauthn/client_data.rb', line 26

def origin
  data["origin"]
end

#token_bindingObject



30
31
32
# File 'lib/webauthn/client_data.rb', line 30

def token_binding
  data["tokenBinding"]
end

#typeObject



18
19
20
# File 'lib/webauthn/client_data.rb', line 18

def type
  data["type"]
end

#valid_token_binding_format?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/webauthn/client_data.rb', line 34

def valid_token_binding_format?
  if token_binding
    token_binding.is_a?(Hash) && VALID_TOKEN_BINDING_STATUSES.include?(token_binding["status"])
  else
    true
  end
end