Sha256: 524017a52073986c5c373ada40d198c3cbe41e695d244d1afda3a6b745bc0578

Contents?: true

Size: 656 Bytes

Versions: 3

Compression:

Stored size: 656 Bytes

Contents

require 'g5_authenticatable_api/token_validator'

module G5AuthenticatableApi
  module Helpers
    module Grape
      def authenticate_user!
        raise_auth_error if !token_validator.valid?
      end

      def warden
        env['warden']
      end

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

      def raise_auth_error
        throw :error, message: 'Unauthorized',
                      status: 401,
                      headers: {'WWW-Authenticate' => token_validator.auth_response_header}
      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/grape.rb
g5_authenticatable_api-0.3.1 lib/g5_authenticatable_api/helpers/grape.rb
g5_authenticatable_api-0.3.0 lib/g5_authenticatable_api/helpers/grape.rb