Class: WebAuthn::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/web_authn/context.rb,
lib/web_authn/context/registration.rb,
lib/web_authn/context/authentication.rb

Direct Known Subclasses

Authentication, Registration

Defined Under Namespace

Classes: Authentication, Registration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_data_json) ⇒ Context

Returns a new instance of Context.



5
6
7
# File 'lib/web_authn/context.rb', line 5

def initialize(client_data_json)
  self.client_data_json = client_data_json
end

Instance Attribute Details

#client_data_jsonObject

Returns the value of attribute client_data_json.



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

def client_data_json
  @client_data_json
end

Class Method Details

.for(encoded_client_data_json, origin:, challenge:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/web_authn/context.rb', line 34

def for(encoded_client_data_json, origin:, challenge:)
  client_data_json = ClientDataJSON.decode encoded_client_data_json

  context = case client_data_json.type
  when 'webauthn.create'
    Registration.new(client_data_json)
  when 'webauthn.get'
    Authentication.new(client_data_json)
  else
    raise InvalidContext, 'Unknown Client Data JSON Type'
  end

  context.verify_session!(origin: origin, challenge: challenge)
end

Instance Method Details

#authentication?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/web_authn/context.rb', line 23

def authentication?
  false
end

#registration?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/web_authn/context.rb', line 19

def registration?
  false
end

#verify_flags!Object



27
28
29
30
31
# File 'lib/web_authn/context.rb', line 27

def verify_flags!
  unless flags.uv? || flags.up?
    raise InvalidAssertion, 'Missing Flag: uv" nor "up"'
  end
end

#verify_session!(origin:, challenge:) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/web_authn/context.rb', line 9

def verify_session!(origin:, challenge:)
  if client_data_json.origin != origin
    raise InvalidContext, 'Invalid Origin'
  end
  if client_data_json.challenge != challenge
    raise InvalidContext, 'Invalid Challenge'
  end
  self
end