Module: Tasker::Authentication::Interface

Included in:
NoneAuthenticator
Defined in:
lib/tasker/authentication/interface.rb

Overview

Interface that host application authenticators must implement

Instance Method Summary collapse

Instance Method Details

#authenticate!(controller) ⇒ void

This method returns an undefined value.

Required: Authenticate the request, raise exception if fails

Parameters:

  • controller (ActionController::Base)

    The controller instance

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/tasker/authentication/interface.rb', line 10

def authenticate!(controller)
  raise NotImplementedError, 'Authenticator must implement #authenticate!'
end

#authenticated?(controller) ⇒ Boolean

Optional: Check if user is authenticated (uses current_user by default)

Parameters:

  • controller (ActionController::Base)

    The controller instance

Returns:

  • (Boolean)

    true if authenticated, false otherwise



24
25
26
# File 'lib/tasker/authentication/interface.rb', line 24

def authenticated?(controller)
  current_user(controller).present?
end

#current_user(controller) ⇒ Object?

Required: Get the current authenticated user

Parameters:

  • controller (ActionController::Base)

    The controller instance

Returns:

  • (Object, nil)

    The authenticated user object or nil

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/tasker/authentication/interface.rb', line 17

def current_user(controller)
  raise NotImplementedError, 'Authenticator must implement #current_user'
end

#validate_configuration(_options = {}) ⇒ Array<String>

Optional: Configuration validation for the authenticator

Parameters:

  • _options (Hash) (defaults to: {})

    Configuration options (unused in default implementation)

Returns:

  • (Array<String>)

    Array of validation error messages, empty if valid



31
32
33
# File 'lib/tasker/authentication/interface.rb', line 31

def validate_configuration(_options = {})
  []
end