Module: Wallaby::AuthenticationConcern

Extended by:
ActiveSupport::Concern
Defined in:
lib/concerns/wallaby/authentication_concern.rb

Overview

Authentication related functions

Instance Method Summary collapse

Instance Method Details

#authenticate_wallaby_user!true

Note:

This is a template method that can be overridden by subclasses

This method will try to call #authenticate_user! from superclass. And it will be run as the first callback before an action.

Examples:

It can be overridden in subclasses:

def authenticate_wallaby_user!
  authenticate_or_request_with_http_basic do |username, password|
    username == 'too_simple' && password == 'too_naive'
  end
end

Returns:

  • (true)

    when user is authenticated successfully

Raises:



45
46
47
48
49
50
# File 'lib/concerns/wallaby/authentication_concern.rb', line 45

def authenticate_wallaby_user!
  authenticated = try :authenticate_user!
  raise NotAuthenticated if authenticated == false

  true
end

#forbidden(exception = nil) ⇒ Object

Forbidden page.

Parameters:

  • exception (Exception) (defaults to: nil)

    comes from rescue_from



60
61
62
# File 'lib/concerns/wallaby/authentication_concern.rb', line 60

def forbidden(exception = nil)
  render_error exception, __callee__
end

#unauthorized(exception = nil) ⇒ Object

Unauthorized page.

Parameters:

  • exception (Exception) (defaults to: nil)

    comes from rescue_from



54
55
56
# File 'lib/concerns/wallaby/authentication_concern.rb', line 54

def unauthorized(exception = nil)
  render_error exception, __callee__
end

#wallaby_userObject

Note:

This is a template method that can be overridden by subclasses

This method will try to call #current_user from superclass.

Examples:

It can be overridden in subclasses:

def wallaby_user
  # NOTE: better to assign user to `@wallaby_user` for better performance:
  @wallaby_user ||= User.new params.slice(:email)
end

Returns:

  • (Object)

    a user object



30
31
32
# File 'lib/concerns/wallaby/authentication_concern.rb', line 30

def wallaby_user
  @wallaby_user ||= try :current_user
end