Class: WebAuthn::ClientDataJSON

Inherits:
Object
  • Object
show all
Defined in:
lib/web_authn/client_data_json.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ ClientDataJSON

Returns a new instance of ClientDataJSON.



5
6
7
8
9
10
# File 'lib/web_authn/client_data_json.rb', line 5

def initialize(attrs = {})
  self.type = attrs[:type]
  self.origin = attrs[:origin]
  self.challenge = attrs[:challenge]
  self.raw = attrs[:raw]
end

Instance Attribute Details

#challengeObject

Returns the value of attribute challenge.



3
4
5
# File 'lib/web_authn/client_data_json.rb', line 3

def challenge
  @challenge
end

#originObject

Returns the value of attribute origin.



3
4
5
# File 'lib/web_authn/client_data_json.rb', line 3

def origin
  @origin
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/web_authn/client_data_json.rb', line 3

def raw
  @raw
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/web_authn/client_data_json.rb', line 3

def type
  @type
end

Class Method Details

.decode(encoded_client_data_json) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/web_authn/client_data_json.rb', line 13

def decode(encoded_client_data_json)
  raw_client_data_json = Base64.urlsafe_decode64 encoded_client_data_json
  attrs = JSON.parse(
    raw_client_data_json
  ).merge(
    raw: raw_client_data_json
  ).with_indifferent_access
  attrs[:challenge] = Base64.urlsafe_decode64 attrs[:challenge]
  new attrs
end