Sha256: 0bcc22572d861cc5b97a48a2968544d55a7382b03567a772230838273cd9a8a2

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

# frozen_string_literal: true
module Apress
  module Api
    module ApiController
      module Authentification
        extend ActiveSupport::Concern

        included do
          attr_reader :current_api_client

          if (Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR == 2) || Rails::VERSION::MAJOR > 4
            before_action :find_session
            before_action :authenticate
          else
            before_filter :find_session
            before_filter :authenticate
          end
        end

        private

        def find_session
          auth_service = AuthService.new(request)
          return unless auth_service.call
          @current_api_client = auth_service.client
        end

        def authenticate
          unauthorized unless @current_api_client
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apress-api-1.24.2 lib/apress/api/api_controller/authentification.rb