Class: Booth::Userland::Sessions::Transitions::Destroy::WebauthAuthenticationVerification

Inherits:
Object
  • Object
show all
Includes:
Concerns::Transition
Defined in:
lib/booth/userland/sessions/transitions/destroy/webauth_authentication_verification.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applicable?(params:) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/booth/userland/sessions/transitions/destroy/webauth_authentication_verification.rb', line 9

def self.applicable?(params:)
  params[:webauth] && params[:type]
end

Instance Method Details

#callObject



13
14
15
16
# File 'lib/booth/userland/sessions/transitions/destroy/webauth_authentication_verification.rb', line 13

def call
  do_find_challenge
    .on_success { do_check_webauth }
end

#do_check_webauthObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/booth/userland/sessions/transitions/destroy/webauth_authentication_verification.rb', line 27

def do_check_webauth
  verification = ::Booth::Webauth::AuthenticationVerification.call(
    request:,
    credential_id: authentication.credential_id,
    challenge: sudo.webauthn_challenge
  )
  return verification if verification.failure?

  if session_id_param
    ::Booth::Sessions::Revoke.call credential_id: authentication.credential_id,
                                   session_id: session_id_param
  else
    ::Booth::Sessions::RevokeAllOthers.call credential_id: authentication.credential_id,
                                            surviving_session_id: authentication.session_id
  end

  Tron.success :session_revocation_successful, public_json: {},
                                               http_status: :created
end

#do_find_challengeObject

Helpers



20
21
22
23
24
25
# File 'lib/booth/userland/sessions/transitions/destroy/webauth_authentication_verification.rb', line 20

def do_find_challenge
  return Tron.success :challenge_ongoing if sudo.webauthn_challenge.present?

  debug { 'There is no corresponding challenge in the session' }
  Tron.failure :no_session_challenge, public_json: {}, http_status: :unprocessable_entity
end

#session_id_paramObject



47
48
49
50
51
# File 'lib/booth/userland/sessions/transitions/destroy/webauth_authentication_verification.rb', line 47

def session_id_param
  # If params[:id] is a UUID, then it's an ID for a `Booth::Models::Session` in the DB.
  # If params[:id] is something else, then it's just a WebAuth Ceremony argument.
  ::Booth::Syntaxes::Uuid.call(request.params[:id], raise_if_invalid: false).uuid
end