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(type:, origin:, challenge:, raw: nil) ⇒ 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(type:, origin:, challenge:, raw: nil)
  self.type = type
  self.origin = origin
  self.challenge = challenge
  self.raw = 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 = Base64.urlsafe_decode64 encoded_client_data_json
  json = JSON.parse(raw).with_indifferent_access
  new(
    type: json[:type],
    origin: json[:origin],
    challenge: Base64.urlsafe_decode64(json[:challenge]),
    raw: raw
  )
end