Sha256: c321b82f2a8714fc4a878256bfb454ba08eb7bba3f8eac7c46d16b4ec4b3ea7e

Contents?: true

Size: 628 Bytes

Versions: 3

Compression:

Stored size: 628 Bytes

Contents

require 'g5_authenticatable_api/token_validator'

module G5AuthenticatableApi
  module Helpers
    module Rails
      def authenticate_api_user!
        raise_auth_error if !token_validator.valid?
      end

      def warden
        request.env['warden']
      end

      private
      def token_validator
        @token_validator ||= TokenValidator.new(request.params, request.headers, warden)
      end

      def raise_auth_error
        response.headers['WWW-Authenticate'] = token_validator.auth_response_header
        render json: {error: 'Unauthorized'},
               status: :unauthorized
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
g5_authenticatable_api-0.3.2 lib/g5_authenticatable_api/helpers/rails.rb
g5_authenticatable_api-0.3.1 lib/g5_authenticatable_api/helpers/rails.rb
g5_authenticatable_api-0.3.0 lib/g5_authenticatable_api/helpers/rails.rb