Class: CommandTower::Workflows::Auth::SignupSession::AuthenticateWorkflow

Inherits:
CommandTower::Workflows::ApplicationWorkflow show all
Defined in:
app/workflows/command_tower/workflows/auth/signup_session/authenticate_workflow.rb

Constant Summary

Constants inherited from CommandTower::Workflows::ApplicationWorkflow

CommandTower::Workflows::ApplicationWorkflow::ALLOWED_RETRY_STRATEGIES, CommandTower::Workflows::ApplicationWorkflow::InvalidTransactionResult, CommandTower::Workflows::ApplicationWorkflow::TransactionFailure

Instance Method Summary collapse

Methods inherited from CommandTower::Workflows::ApplicationWorkflow

call, call_from_job, continuation_max_attempts, declared_retry_strategy, mark_impersonation_activity!, retry_strategy, validate_retry_strategy!

Methods included from Impersonation::ActivityDeclaration

included

Methods included from Logging::LifecycleDeclaration

included

Methods included from Execution::ContextAccess

#audit, #execution_context, #log_debug, #log_error, #log_info, #log_warn, #publish_event

Methods included from Transactional

#fail_transaction!, #transaction

Instance Method Details

#call(request:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/workflows/command_tower/workflows/auth/signup_session/authenticate_workflow.rb', line 10

def call(request:)
  token_data = CommandTower::Signup::AuthorizationHelper.extract_token(request)

  if token_data[:error]
    return failure(errors: [extraction_error(token_data[:error])], http_status: :unauthorized)
  end

  client_ip = CommandTower::Services::Auth::ClientIpResolver.call(request: request)
  validate_result = CommandTower::Services::Auth::SignupSession::Validate.call(
    token: token_data[:token],
    client_ip: client_ip
  )

  unless validate_result.success?
    return failure(
      errors: validate_result.errors,
      http_status: SignupErrorStatus.http_status_for(validate_result.errors.first)
    )
  end

  success(
    payload: { signup_session: validate_result.data[:signup_session] },
    http_status: :ok
  )
end