Sha256: 9e175d119922519946c59068078d1bb412dd97b54c605c91664c23bedb2042dc

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

require 'active_support/concern'
require 'token_authenticate_me/concerns/controllers/authenticateable'
require 'token_authenticate_me/header_authentication'
require 'token_authenticate_me/param_authentication'

module TokenAuthenticateMe
  module Concerns
    module Controllers
      module TokenAuthenticateable
        extend ActiveSupport::Concern

        include TokenAuthenticateMe::Concerns::Controllers::Authenticateable

        protected

        def authenticated_session
          @session ||= (authenticate_with_header || authenticate_with_params)
        end

        def authenticate_with_header
          header_authentication = TokenAuthenticateMe::HeaderAuthentication.new(controller: self)
          header_authentication.authenticate
        end

        def authenticate_with_params
          header_authentication = TokenAuthenticateMe::ParamAuthentication.new(controller: self)
          header_authentication.authenticate
        end

        def render_unauthorized
          headers['WWW-Authenticate'] = 'Token realm="Application"'
          render json: 'Bad credentials', status: 401
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
token_authenticate_me-0.9.2 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.11.2 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.11.1 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.11.0 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.10.0 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.9.1 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.9.0 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.8.0 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb
token_authenticate_me-0.7.0 lib/token_authenticate_me/concerns/controllers/token_authenticateable.rb