Class: Booth::Logins::Transitions::Create::WebauthAuthenticationInitiation

Inherits:
Object
  • Object
show all
Includes:
Concerns::Transition
Defined in:
lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.applicable?(params:) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb', line 8

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

Instance Method Details

#callObject



12
13
14
15
16
# File 'lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb', line 12

def call
  do_check_stale_session
    .on_success { do_find_credential }
    .on_success { do_check_webauth }
end

#do_check_stale_sessionObject

Helpers



20
21
22
23
24
25
26
# File 'lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb', line 20

def do_check_stale_session
  return Tron.success :session_not_stale unless storage.timed_out?

  public_message = I18n.t('booth.login_timeout', lifespan_minutes: (storage.lifespan / 60))
  Tron.failure :stale_session, step: :enter_username,
                               public_message:
end

#do_check_webauthObject



36
37
38
39
40
41
42
43
44
# File 'lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb', line 36

def do_check_webauth
  debug { 'Preparing webauth challenge...' }
  challenging = Booth::Credentials::WebauthChallenge.call(credential: @credential)
  result = Tron.success :webauth_for_you, public_json: challenging.options_for_get, http_status: :ok
  debug { "The challenge is #{challenging.challenge}" }
  storage.webauthn_challenge = challenging.challenge
  debug { "Responding with JSON: #{result.public_json}" }
  result
end

#do_find_credentialObject



28
29
30
31
32
33
34
# File 'lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb', line 28

def do_find_credential
  @credential = storage.credential_for_username
  return Tron.success :found_credential if @credential

  debug { 'I do not know the credential for this username' }
  Tron.failure :missing_credential
end

#storageObject



46
47
48
# File 'lib/booth/userland/logins/transitions/create/webauth_authentication_initiation.rb', line 46

def storage
  request.storage.
end