Sha256: 075ffc6b616014f0ce1d5151b23f60a3238e7daeabc9e48ece07b1a911a3a88e

Contents?: true

Size: 755 Bytes

Versions: 10

Compression:

Stored size: 755 Bytes

Contents

class ApplicationController < ActionController::API
  include ActionController::HttpAuthentication::Token::ControllerMethods

  before_action :set_current_request_details
  before_action :authenticate
  <%- if options.sudoable? %>
  def require_sudo
    unless Current.session.sudo?
      render json: { error: "Enter your password to continue" }, status: :forbidden
    end
  end
  <%- end -%>

  private
    def authenticate
      if session = authenticate_with_http_token { |token, _| Session.find_signed(token) }
        Current.session = session
      else
        request_http_token_authentication
      end
    end

    def set_current_request_details
      Current.user_agent = request.user_agent
      Current.ip_address = request.ip
    end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
authentication-zero-2.12.6 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.12.5 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.12.4 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.12.3 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.12.2 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.12.1 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.12.0 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.11.2 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.11.1 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.11.0 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt